diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7d51712 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*.csv +.db +*.txt diff --git a/README.md b/README.md index b2cb5fc..8b13789 100644 --- a/README.md +++ b/README.md @@ -1,93 +1 @@ -# am-scripts - - -## Getting started - -To make it easy for you to get started with GitLab, here's a list of recommended next steps. - -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! - -## Add your files - -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: - -``` -cd existing_repo -git remote add origin https://gitlab.artefactual.com/dcosme/am-scripts.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://gitlab.artefactual.com/dcosme/am-scripts/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README - -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. diff --git a/bobgen.yaml b/bobgen.yaml new file mode 100644 index 0000000..c23097f --- /dev/null +++ b/bobgen.yaml @@ -0,0 +1,30 @@ +mysql: + dsn: "root:12345@tcp(localhost:62001)/SS" + +plugins: + dbinfo: + disabled: true + pkgname: "dbinfo" + destination: "./database/mcp/dbinfo" + enums: + disabled: false + pkgname: "enums" + destination: "./database/mcp/enums" + models: + disabled: false + pkgname: "models" + destination: "./database/mcp/models" + factory: + disabled: true + pkgname: "factory" + destination: "./database/mcp/factory" + dberrors: + disabled: false + pkgname: "dberrors" + destination: "./database/mcp/dberrors" + where: + disabled: false + loaders: + disabled: false + joins: + disabled: false diff --git a/database/mcp/dberrors/administration_settings.bob.go b/database/mcp/dberrors/administration_settings.bob.go new file mode 100644 index 0000000..1d7e2a8 --- /dev/null +++ b/database/mcp/dberrors/administration_settings.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var AdministrationSettingErrors = &administrationSettingErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "administration_settings", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueName: &UniqueConstraintError{ + schema: "", + table: "administration_settings", + columns: []string{"name"}, + s: "name", + }, +} + +type administrationSettingErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueName *UniqueConstraintError +} diff --git a/database/mcp/dberrors/auth_group.bob.go b/database/mcp/dberrors/auth_group.bob.go new file mode 100644 index 0000000..35c596d --- /dev/null +++ b/database/mcp/dberrors/auth_group.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var AuthGroupErrors = &authGroupErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "auth_group", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueName: &UniqueConstraintError{ + schema: "", + table: "auth_group", + columns: []string{"name"}, + s: "name", + }, +} + +type authGroupErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueName *UniqueConstraintError +} diff --git a/database/mcp/dberrors/auth_group_permissions.bob.go b/database/mcp/dberrors/auth_group_permissions.bob.go new file mode 100644 index 0000000..caa7b74 --- /dev/null +++ b/database/mcp/dberrors/auth_group_permissions.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var AuthGroupPermissionErrors = &authGroupPermissionErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "auth_group_permissions", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueAuthGroupPermissionsGroupIdPermissionId0cd325b0Uniq: &UniqueConstraintError{ + schema: "", + table: "auth_group_permissions", + columns: []string{"group_id", "permission_id"}, + s: "auth_group_permissions_group_id_permission_id_0cd325b0_uniq", + }, +} + +type authGroupPermissionErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueAuthGroupPermissionsGroupIdPermissionId0cd325b0Uniq *UniqueConstraintError +} diff --git a/database/mcp/dberrors/auth_permission.bob.go b/database/mcp/dberrors/auth_permission.bob.go new file mode 100644 index 0000000..3cfef8e --- /dev/null +++ b/database/mcp/dberrors/auth_permission.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var AuthPermissionErrors = &authPermissionErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "auth_permission", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueAuthPermissionContentTypeIdCodename01ab375aUniq: &UniqueConstraintError{ + schema: "", + table: "auth_permission", + columns: []string{"content_type_id", "codename"}, + s: "auth_permission_content_type_id_codename_01ab375a_uniq", + }, +} + +type authPermissionErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueAuthPermissionContentTypeIdCodename01ab375aUniq *UniqueConstraintError +} diff --git a/database/mcp/dberrors/auth_user.bob.go b/database/mcp/dberrors/auth_user.bob.go new file mode 100644 index 0000000..b933676 --- /dev/null +++ b/database/mcp/dberrors/auth_user.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var AuthUserErrors = &authUserErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "auth_user", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUsername: &UniqueConstraintError{ + schema: "", + table: "auth_user", + columns: []string{"username"}, + s: "username", + }, +} + +type authUserErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUsername *UniqueConstraintError +} diff --git a/database/mcp/dberrors/auth_user_groups.bob.go b/database/mcp/dberrors/auth_user_groups.bob.go new file mode 100644 index 0000000..4dc8413 --- /dev/null +++ b/database/mcp/dberrors/auth_user_groups.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var AuthUserGroupErrors = &authUserGroupErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "auth_user_groups", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueAuthUserGroupsUserIdGroupId94350c0cUniq: &UniqueConstraintError{ + schema: "", + table: "auth_user_groups", + columns: []string{"user_id", "group_id"}, + s: "auth_user_groups_user_id_group_id_94350c0c_uniq", + }, +} + +type authUserGroupErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueAuthUserGroupsUserIdGroupId94350c0cUniq *UniqueConstraintError +} diff --git a/database/mcp/dberrors/auth_user_user_permissions.bob.go b/database/mcp/dberrors/auth_user_user_permissions.bob.go new file mode 100644 index 0000000..5f55490 --- /dev/null +++ b/database/mcp/dberrors/auth_user_user_permissions.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var AuthUserUserPermissionErrors = &authUserUserPermissionErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "auth_user_user_permissions", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueAuthUserUserPermissionsUserIdPermissionId14a6b632Uniq: &UniqueConstraintError{ + schema: "", + table: "auth_user_user_permissions", + columns: []string{"user_id", "permission_id"}, + s: "auth_user_user_permissions_user_id_permission_id_14a6b632_uniq", + }, +} + +type authUserUserPermissionErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueAuthUserUserPermissionsUserIdPermissionId14a6b632Uniq *UniqueConstraintError +} diff --git a/database/mcp/dberrors/bob_errors.bob.go b/database/mcp/dberrors/bob_errors.bob.go new file mode 100644 index 0000000..3ad7ea4 --- /dev/null +++ b/database/mcp/dberrors/bob_errors.bob.go @@ -0,0 +1,36 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +import ( + "strings" + + mysqlDriver "github.com/go-sql-driver/mysql" +) + +// ErrUniqueConstraint captures all unique constraint errors by explicitly leaving `s` empty. +var ErrUniqueConstraint = &UniqueConstraintError{s: ""} + +type UniqueConstraintError struct { + // schema is the schema where the unique constraint is defined. + schema string + // table is the name of the table where the unique constraint is defined. + table string + // columns are the columns constituting the unique constraint. + columns []string + // s is a string uniquely identifying the constraint in the raw error message returned from the database. + s string +} + +func (e *UniqueConstraintError) Error() string { + return e.s +} + +func (e *UniqueConstraintError) Is(target error) bool { + err, ok := target.(*mysqlDriver.MySQLError) + if !ok { + return false + } + return err.Number == 1062 && strings.Contains(err.Message, e.s) +} diff --git a/database/mcp/dberrors/bob_main.bob_test.go b/database/mcp/dberrors/bob_main.bob_test.go new file mode 100644 index 0000000..886fbd5 --- /dev/null +++ b/database/mcp/dberrors/bob_main.bob_test.go @@ -0,0 +1,9 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +import "github.com/stephenafamo/bob" + +// Set the testDB to enable tests that use the database +var testDB bob.Transactor[bob.Tx] diff --git a/database/mcp/dberrors/django_admin_log.bob.go b/database/mcp/dberrors/django_admin_log.bob.go new file mode 100644 index 0000000..33d7db2 --- /dev/null +++ b/database/mcp/dberrors/django_admin_log.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var DjangoAdminLogErrors = &djangoAdminLogErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "django_admin_log", + columns: []string{"id"}, + s: "PRIMARY", + }, +} + +type djangoAdminLogErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/mcp/dberrors/django_content_type.bob.go b/database/mcp/dberrors/django_content_type.bob.go new file mode 100644 index 0000000..12f7270 --- /dev/null +++ b/database/mcp/dberrors/django_content_type.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var DjangoContentTypeErrors = &djangoContentTypeErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "django_content_type", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueDjangoContentTypeAppLabelModel76bd3d3bUniq: &UniqueConstraintError{ + schema: "", + table: "django_content_type", + columns: []string{"app_label", "model"}, + s: "django_content_type_app_label_model_76bd3d3b_uniq", + }, +} + +type djangoContentTypeErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueDjangoContentTypeAppLabelModel76bd3d3bUniq *UniqueConstraintError +} diff --git a/database/mcp/dberrors/django_migrations.bob.go b/database/mcp/dberrors/django_migrations.bob.go new file mode 100644 index 0000000..da2757f --- /dev/null +++ b/database/mcp/dberrors/django_migrations.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var DjangoMigrationErrors = &djangoMigrationErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "django_migrations", + columns: []string{"id"}, + s: "PRIMARY", + }, +} + +type djangoMigrationErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/mcp/dberrors/django_session.bob.go b/database/mcp/dberrors/django_session.bob.go new file mode 100644 index 0000000..746a439 --- /dev/null +++ b/database/mcp/dberrors/django_session.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var DjangoSessionErrors = &djangoSessionErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "django_session", + columns: []string{"session_key"}, + s: "PRIMARY", + }, +} + +type djangoSessionErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/mcp/dberrors/django_site.bob.go b/database/mcp/dberrors/django_site.bob.go new file mode 100644 index 0000000..a6151db --- /dev/null +++ b/database/mcp/dberrors/django_site.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var DjangoSiteErrors = &djangoSiteErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "django_site", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueDjangoSiteDomainA2e37b91Uniq: &UniqueConstraintError{ + schema: "", + table: "django_site", + columns: []string{"domain"}, + s: "django_site_domain_a2e37b91_uniq", + }, +} + +type djangoSiteErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueDjangoSiteDomainA2e37b91Uniq *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_archipelago.bob.go b/database/mcp/dberrors/locations_archipelago.bob.go new file mode 100644 index 0000000..5b74b98 --- /dev/null +++ b/database/mcp/dberrors/locations_archipelago.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsArchipelagoErrors = &locationsArchipelagoErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_archipelago", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_archipelago", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsArchipelagoErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_arkivum.bob.go b/database/mcp/dberrors/locations_arkivum.bob.go new file mode 100644 index 0000000..a1b3267 --- /dev/null +++ b/database/mcp/dberrors/locations_arkivum.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsArkivumErrors = &locationsArkivumErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_arkivum", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_arkivum", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsArkivumErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_async.bob.go b/database/mcp/dberrors/locations_async.bob.go new file mode 100644 index 0000000..c1690cc --- /dev/null +++ b/database/mcp/dberrors/locations_async.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsAsyncErrors = &locationsAsyncErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_async", + columns: []string{"id"}, + s: "PRIMARY", + }, +} + +type locationsAsyncErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_callback.bob.go b/database/mcp/dberrors/locations_callback.bob.go new file mode 100644 index 0000000..2100663 --- /dev/null +++ b/database/mcp/dberrors/locations_callback.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsCallbackErrors = &locationsCallbackErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_callback", + columns: []string{"id"}, + s: "PRIMARY", + }, +} + +type locationsCallbackErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_dataverse.bob.go b/database/mcp/dberrors/locations_dataverse.bob.go new file mode 100644 index 0000000..116f8f1 --- /dev/null +++ b/database/mcp/dberrors/locations_dataverse.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsDataverseErrors = &locationsDataverseErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_dataverse", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_dataverse", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsDataverseErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_dspace.bob.go b/database/mcp/dberrors/locations_dspace.bob.go new file mode 100644 index 0000000..b72a25c --- /dev/null +++ b/database/mcp/dberrors/locations_dspace.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsDspaceErrors = &locationsDspaceErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_dspace", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_dspace", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsDspaceErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_dspacerest.bob.go b/database/mcp/dberrors/locations_dspacerest.bob.go new file mode 100644 index 0000000..39a2cb5 --- /dev/null +++ b/database/mcp/dberrors/locations_dspacerest.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsDspacerestErrors = &locationsDspacerestErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_dspacerest", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_dspacerest", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsDspacerestErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_duracloud.bob.go b/database/mcp/dberrors/locations_duracloud.bob.go new file mode 100644 index 0000000..5cd35a4 --- /dev/null +++ b/database/mcp/dberrors/locations_duracloud.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsDuracloudErrors = &locationsDuracloudErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_duracloud", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_duracloud", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsDuracloudErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_event.bob.go b/database/mcp/dberrors/locations_event.bob.go new file mode 100644 index 0000000..d79e67a --- /dev/null +++ b/database/mcp/dberrors/locations_event.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsEventErrors = &locationsEventErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_event", + columns: []string{"id"}, + s: "PRIMARY", + }, +} + +type locationsEventErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_fedora.bob.go b/database/mcp/dberrors/locations_fedora.bob.go new file mode 100644 index 0000000..d11576f --- /dev/null +++ b/database/mcp/dberrors/locations_fedora.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsFedoraErrors = &locationsFedoraErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_fedora", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_fedora", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsFedoraErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_file.bob.go b/database/mcp/dberrors/locations_file.bob.go new file mode 100644 index 0000000..9caf74a --- /dev/null +++ b/database/mcp/dberrors/locations_file.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsFileErrors = &locationsFileErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_file", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUuid: &UniqueConstraintError{ + schema: "", + table: "locations_file", + columns: []string{"uuid"}, + s: "uuid", + }, +} + +type locationsFileErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUuid *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_fixitylog.bob.go b/database/mcp/dberrors/locations_fixitylog.bob.go new file mode 100644 index 0000000..bc06555 --- /dev/null +++ b/database/mcp/dberrors/locations_fixitylog.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsFixitylogErrors = &locationsFixitylogErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_fixitylog", + columns: []string{"id"}, + s: "PRIMARY", + }, +} + +type locationsFixitylogErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_gpg.bob.go b/database/mcp/dberrors/locations_gpg.bob.go new file mode 100644 index 0000000..cfd0802 --- /dev/null +++ b/database/mcp/dberrors/locations_gpg.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsGPGErrors = &locationsGPGErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_gpg", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_gpg", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsGPGErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_localfilesystem.bob.go b/database/mcp/dberrors/locations_localfilesystem.bob.go new file mode 100644 index 0000000..16c8142 --- /dev/null +++ b/database/mcp/dberrors/locations_localfilesystem.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsLocalfilesystemErrors = &locationsLocalfilesystemErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_localfilesystem", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_localfilesystem", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsLocalfilesystemErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_location.bob.go b/database/mcp/dberrors/locations_location.bob.go new file mode 100644 index 0000000..8aba8ca --- /dev/null +++ b/database/mcp/dberrors/locations_location.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsLocationErrors = &locationsLocationErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_location", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUuid: &UniqueConstraintError{ + schema: "", + table: "locations_location", + columns: []string{"uuid"}, + s: "uuid", + }, +} + +type locationsLocationErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUuid *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_location_replicators.bob.go b/database/mcp/dberrors/locations_location_replicators.bob.go new file mode 100644 index 0000000..e737ec8 --- /dev/null +++ b/database/mcp/dberrors/locations_location_replicators.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsLocationReplicatorErrors = &locationsLocationReplicatorErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_location_replicators", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueLocationsLocationRepliFromLocationIdToLoca5f763358Uniq: &UniqueConstraintError{ + schema: "", + table: "locations_location_replicators", + columns: []string{"from_location_id", "to_location_id"}, + s: "locations_location_repli_from_location_id_to_loca_5f763358_uniq", + }, +} + +type locationsLocationReplicatorErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueLocationsLocationRepliFromLocationIdToLoca5f763358Uniq *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_locationpipeline.bob.go b/database/mcp/dberrors/locations_locationpipeline.bob.go new file mode 100644 index 0000000..2257404 --- /dev/null +++ b/database/mcp/dberrors/locations_locationpipeline.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsLocationpipelineErrors = &locationsLocationpipelineErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_locationpipeline", + columns: []string{"id"}, + s: "PRIMARY", + }, +} + +type locationsLocationpipelineErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_lockssomatic.bob.go b/database/mcp/dberrors/locations_lockssomatic.bob.go new file mode 100644 index 0000000..87549d6 --- /dev/null +++ b/database/mcp/dberrors/locations_lockssomatic.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsLockssomaticErrors = &locationsLockssomaticErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_lockssomatic", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_lockssomatic", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsLockssomaticErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_nfs.bob.go b/database/mcp/dberrors/locations_nfs.bob.go new file mode 100644 index 0000000..d57f7fb --- /dev/null +++ b/database/mcp/dberrors/locations_nfs.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsNFErrors = &locationsNFErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_nfs", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_nfs", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsNFErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_offlinereplicastaging.bob.go b/database/mcp/dberrors/locations_offlinereplicastaging.bob.go new file mode 100644 index 0000000..abb7316 --- /dev/null +++ b/database/mcp/dberrors/locations_offlinereplicastaging.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsOfflinereplicastagingErrors = &locationsOfflinereplicastagingErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_offlinereplicastaging", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_offlinereplicastaging", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsOfflinereplicastagingErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_package.bob.go b/database/mcp/dberrors/locations_package.bob.go new file mode 100644 index 0000000..d71fb8f --- /dev/null +++ b/database/mcp/dberrors/locations_package.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsPackageErrors = &locationsPackageErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_package", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUuid: &UniqueConstraintError{ + schema: "", + table: "locations_package", + columns: []string{"uuid"}, + s: "uuid", + }, +} + +type locationsPackageErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUuid *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_package_related_packages.bob.go b/database/mcp/dberrors/locations_package_related_packages.bob.go new file mode 100644 index 0000000..431d031 --- /dev/null +++ b/database/mcp/dberrors/locations_package_related_packages.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsPackageRelatedPackageErrors = &locationsPackageRelatedPackageErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_package_related_packages", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueLocationsPackageRelateFromPackageIdToPacka1f820ccfUniq: &UniqueConstraintError{ + schema: "", + table: "locations_package_related_packages", + columns: []string{"from_package_id", "to_package_id"}, + s: "locations_package_relate_from_package_id_to_packa_1f820ccf_uniq", + }, +} + +type locationsPackageRelatedPackageErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueLocationsPackageRelateFromPackageIdToPacka1f820ccfUniq *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_packagedownloadtask.bob.go b/database/mcp/dberrors/locations_packagedownloadtask.bob.go new file mode 100644 index 0000000..b949169 --- /dev/null +++ b/database/mcp/dberrors/locations_packagedownloadtask.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsPackagedownloadtaskErrors = &locationsPackagedownloadtaskErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_packagedownloadtask", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUuid: &UniqueConstraintError{ + schema: "", + table: "locations_packagedownloadtask", + columns: []string{"uuid"}, + s: "uuid", + }, +} + +type locationsPackagedownloadtaskErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUuid *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_packagedownloadtaskfile.bob.go b/database/mcp/dberrors/locations_packagedownloadtaskfile.bob.go new file mode 100644 index 0000000..097eeeb --- /dev/null +++ b/database/mcp/dberrors/locations_packagedownloadtaskfile.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsPackagedownloadtaskfileErrors = &locationsPackagedownloadtaskfileErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_packagedownloadtaskfile", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUuid: &UniqueConstraintError{ + schema: "", + table: "locations_packagedownloadtaskfile", + columns: []string{"uuid"}, + s: "uuid", + }, +} + +type locationsPackagedownloadtaskfileErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUuid *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_pipeline.bob.go b/database/mcp/dberrors/locations_pipeline.bob.go new file mode 100644 index 0000000..1baf6d2 --- /dev/null +++ b/database/mcp/dberrors/locations_pipeline.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsPipelineErrors = &locationsPipelineErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_pipeline", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUuid: &UniqueConstraintError{ + schema: "", + table: "locations_pipeline", + columns: []string{"uuid"}, + s: "uuid", + }, +} + +type locationsPipelineErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUuid *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_pipelinelocalfs.bob.go b/database/mcp/dberrors/locations_pipelinelocalfs.bob.go new file mode 100644 index 0000000..e0856fa --- /dev/null +++ b/database/mcp/dberrors/locations_pipelinelocalfs.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsPipelinelocalfErrors = &locationsPipelinelocalfErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_pipelinelocalfs", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_pipelinelocalfs", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsPipelinelocalfErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_rclone.bob.go b/database/mcp/dberrors/locations_rclone.bob.go new file mode 100644 index 0000000..64dfd2e --- /dev/null +++ b/database/mcp/dberrors/locations_rclone.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsRcloneErrors = &locationsRcloneErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_rclone", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_rclone", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsRcloneErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_s3.bob.go b/database/mcp/dberrors/locations_s3.bob.go new file mode 100644 index 0000000..40fd789 --- /dev/null +++ b/database/mcp/dberrors/locations_s3.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsS3Errors = &locationsS3Errors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_s3", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_s3", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsS3Errors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_space.bob.go b/database/mcp/dberrors/locations_space.bob.go new file mode 100644 index 0000000..5c4c663 --- /dev/null +++ b/database/mcp/dberrors/locations_space.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsSpaceErrors = &locationsSpaceErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_space", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUuid: &UniqueConstraintError{ + schema: "", + table: "locations_space", + columns: []string{"uuid"}, + s: "uuid", + }, +} + +type locationsSpaceErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUuid *UniqueConstraintError +} diff --git a/database/mcp/dberrors/locations_swift.bob.go b/database/mcp/dberrors/locations_swift.bob.go new file mode 100644 index 0000000..2618cdd --- /dev/null +++ b/database/mcp/dberrors/locations_swift.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsSwiftErrors = &locationsSwiftErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_swift", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_swift", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsSwiftErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/mcp/dberrors/tastypie_apiaccess.bob.go b/database/mcp/dberrors/tastypie_apiaccess.bob.go new file mode 100644 index 0000000..c13e866 --- /dev/null +++ b/database/mcp/dberrors/tastypie_apiaccess.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var TastypieApiaccessErrors = &tastypieApiaccessErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "tastypie_apiaccess", + columns: []string{"id"}, + s: "PRIMARY", + }, +} + +type tastypieApiaccessErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/mcp/dberrors/tastypie_apikey.bob.go b/database/mcp/dberrors/tastypie_apikey.bob.go new file mode 100644 index 0000000..0368fb9 --- /dev/null +++ b/database/mcp/dberrors/tastypie_apikey.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var TastypieApikeyErrors = &tastypieApikeyErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "tastypie_apikey", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUserId: &UniqueConstraintError{ + schema: "", + table: "tastypie_apikey", + columns: []string{"user_id"}, + s: "user_id", + }, +} + +type tastypieApikeyErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUserId *UniqueConstraintError +} diff --git a/database/mcp/models/administration_settings.bob.go b/database/mcp/models/administration_settings.bob.go new file mode 100644 index 0000000..06bed73 --- /dev/null +++ b/database/mcp/models/administration_settings.bob.go @@ -0,0 +1,396 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" +) + +// AdministrationSetting is an object representing the database table. +type AdministrationSetting struct { + ID int32 `db:"id,pk,autoincr" ` + Name string `db:"name" ` + Value null.Val[string] `db:"value" ` +} + +// AdministrationSettingSlice is an alias for a slice of pointers to AdministrationSetting. +// This should almost always be used instead of []*AdministrationSetting. +type AdministrationSettingSlice []*AdministrationSetting + +// AdministrationSettings contains methods to work with the administration_settings table +var AdministrationSettings = mysql.NewTablex[*AdministrationSetting, AdministrationSettingSlice, *AdministrationSettingSetter]("administration_settings", buildAdministrationSettingColumns("administration_settings"), []string{"id"}, []string{"name"}) + +// AdministrationSettingsQuery is a query on the administration_settings table +type AdministrationSettingsQuery = *mysql.ViewQuery[*AdministrationSetting, AdministrationSettingSlice] + +func buildAdministrationSettingColumns(alias string) administrationSettingColumns { + return administrationSettingColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "name", "value", + ).WithParent("administration_settings"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Name: mysql.Quote(alias, "name"), + Value: mysql.Quote(alias, "value"), + } +} + +type administrationSettingColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Name mysql.Expression + Value mysql.Expression +} + +func (c administrationSettingColumns) Alias() string { + return c.tableAlias +} + +func (administrationSettingColumns) AliasedAs(alias string) administrationSettingColumns { + return buildAdministrationSettingColumns(alias) +} + +// AdministrationSettingSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type AdministrationSettingSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Name omit.Val[string] `db:"name" ` + Value omitnull.Val[string] `db:"value" ` +} + +func (s AdministrationSettingSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Name.IsValue() { + vals = append(vals, "name") + } + if !s.Value.IsUnset() { + vals = append(vals, "value") + } + return vals +} + +func (s AdministrationSettingSetter) Overwrite(t *AdministrationSetting) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Name.IsValue() { + t.Name = s.Name.MustGet() + } + if !s.Value.IsUnset() { + t.Value = s.Value.MustGetNull() + } +} + +func (s *AdministrationSettingSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AdministrationSettings.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Name.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Name.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Value.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Value.MustGetNull()).WriteSQL(ctx, w, d, start) + })) +} + +func (s AdministrationSettingSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("administration_settings")...) +} + +func (s AdministrationSettingSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Name.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "name")...), + mysql.Arg(s.Name), + }}) + } + + if !s.Value.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "value")...), + mysql.Arg(s.Value), + }}) + } + + return exprs +} + +// FindAdministrationSetting retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindAdministrationSetting(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*AdministrationSetting, error) { + if len(cols) == 0 { + return AdministrationSettings.Query( + sm.Where(AdministrationSettings.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return AdministrationSettings.Query( + sm.Where(AdministrationSettings.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(AdministrationSettings.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// AdministrationSettingExists checks the presence of a single record by primary key +func AdministrationSettingExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return AdministrationSettings.Query( + sm.Where(AdministrationSettings.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after AdministrationSetting is retrieved from the database +func (o *AdministrationSetting) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AdministrationSettings.AfterSelectHooks.RunHooks(ctx, exec, AdministrationSettingSlice{o}) + case bob.QueryTypeInsert: + ctx, err = AdministrationSettings.AfterInsertHooks.RunHooks(ctx, exec, AdministrationSettingSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = AdministrationSettings.AfterUpdateHooks.RunHooks(ctx, exec, AdministrationSettingSlice{o}) + case bob.QueryTypeDelete: + ctx, err = AdministrationSettings.AfterDeleteHooks.RunHooks(ctx, exec, AdministrationSettingSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the AdministrationSetting +func (o *AdministrationSetting) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *AdministrationSetting) pkEQ() dialect.Expression { + return mysql.Quote("administration_settings", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the AdministrationSetting +func (o *AdministrationSetting) Update(ctx context.Context, exec bob.Executor, s *AdministrationSettingSetter) error { + _, err := AdministrationSettings.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single AdministrationSetting record with an executor +func (o *AdministrationSetting) Delete(ctx context.Context, exec bob.Executor) error { + _, err := AdministrationSettings.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the AdministrationSetting using the executor +func (o *AdministrationSetting) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := AdministrationSettings.Query( + sm.Where(AdministrationSettings.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + + *o = *o2 + + return nil +} + +// AfterQueryHook is called after AdministrationSettingSlice is retrieved from the database +func (o AdministrationSettingSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AdministrationSettings.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = AdministrationSettings.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = AdministrationSettings.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = AdministrationSettings.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o AdministrationSettingSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("administration_settings", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o AdministrationSettingSlice) copyMatchingRows(from ...*AdministrationSetting) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o AdministrationSettingSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AdministrationSettings.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AdministrationSetting: + o.copyMatchingRows(retrieved) + case []*AdministrationSetting: + o.copyMatchingRows(retrieved...) + case AdministrationSettingSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AdministrationSetting or a slice of AdministrationSetting + // then run the AfterUpdateHooks on the slice + _, err = AdministrationSettings.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o AdministrationSettingSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AdministrationSettings.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AdministrationSetting: + o.copyMatchingRows(retrieved) + case []*AdministrationSetting: + o.copyMatchingRows(retrieved...) + case AdministrationSettingSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AdministrationSetting or a slice of AdministrationSetting + // then run the AfterDeleteHooks on the slice + _, err = AdministrationSettings.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o AdministrationSettingSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals AdministrationSettingSetter) error { + _, err := AdministrationSettings.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o AdministrationSettingSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := AdministrationSettings.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o AdministrationSettingSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := AdministrationSettings.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +type administrationSettingWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Name mysql.WhereMod[Q, string] + Value mysql.WhereNullMod[Q, string] +} + +func (administrationSettingWhere[Q]) AliasedAs(alias string) administrationSettingWhere[Q] { + return buildAdministrationSettingWhere[Q](buildAdministrationSettingColumns(alias)) +} + +func buildAdministrationSettingWhere[Q mysql.Filterable](cols administrationSettingColumns) administrationSettingWhere[Q] { + return administrationSettingWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Name: mysql.Where[Q, string](cols.Name), + Value: mysql.WhereNull[Q, string](cols.Value), + } +} diff --git a/database/mcp/models/auth_group.bob.go b/database/mcp/models/auth_group.bob.go new file mode 100644 index 0000000..3143b0f --- /dev/null +++ b/database/mcp/models/auth_group.bob.go @@ -0,0 +1,795 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// AuthGroup is an object representing the database table. +type AuthGroup struct { + ID int32 `db:"id,pk,autoincr" ` + Name string `db:"name" ` + + R authGroupR `db:"-" ` +} + +// AuthGroupSlice is an alias for a slice of pointers to AuthGroup. +// This should almost always be used instead of []*AuthGroup. +type AuthGroupSlice []*AuthGroup + +// AuthGroups contains methods to work with the auth_group table +var AuthGroups = mysql.NewTablex[*AuthGroup, AuthGroupSlice, *AuthGroupSetter]("auth_group", buildAuthGroupColumns("auth_group"), []string{"id"}, []string{"name"}) + +// AuthGroupsQuery is a query on the auth_group table +type AuthGroupsQuery = *mysql.ViewQuery[*AuthGroup, AuthGroupSlice] + +// authGroupR is where relationships are stored. +type authGroupR struct { + GroupAuthGroupPermissions AuthGroupPermissionSlice // auth_group_permissions_group_id_b120cbf9_fk_auth_group_id + GroupAuthUserGroups AuthUserGroupSlice // auth_user_groups_group_id_97559544_fk_auth_group_id +} + +func buildAuthGroupColumns(alias string) authGroupColumns { + return authGroupColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "name", + ).WithParent("auth_group"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Name: mysql.Quote(alias, "name"), + } +} + +type authGroupColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Name mysql.Expression +} + +func (c authGroupColumns) Alias() string { + return c.tableAlias +} + +func (authGroupColumns) AliasedAs(alias string) authGroupColumns { + return buildAuthGroupColumns(alias) +} + +// AuthGroupSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type AuthGroupSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Name omit.Val[string] `db:"name" ` +} + +func (s AuthGroupSetter) SetColumns() []string { + vals := make([]string, 0, 2) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Name.IsValue() { + vals = append(vals, "name") + } + return vals +} + +func (s AuthGroupSetter) Overwrite(t *AuthGroup) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Name.IsValue() { + t.Name = s.Name.MustGet() + } +} + +func (s *AuthGroupSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthGroups.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Name.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Name.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s AuthGroupSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("auth_group")...) +} + +func (s AuthGroupSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 2) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Name.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "name")...), + mysql.Arg(s.Name), + }}) + } + + return exprs +} + +// FindAuthGroup retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindAuthGroup(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*AuthGroup, error) { + if len(cols) == 0 { + return AuthGroups.Query( + sm.Where(AuthGroups.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return AuthGroups.Query( + sm.Where(AuthGroups.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(AuthGroups.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// AuthGroupExists checks the presence of a single record by primary key +func AuthGroupExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return AuthGroups.Query( + sm.Where(AuthGroups.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after AuthGroup is retrieved from the database +func (o *AuthGroup) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthGroups.AfterSelectHooks.RunHooks(ctx, exec, AuthGroupSlice{o}) + case bob.QueryTypeInsert: + ctx, err = AuthGroups.AfterInsertHooks.RunHooks(ctx, exec, AuthGroupSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = AuthGroups.AfterUpdateHooks.RunHooks(ctx, exec, AuthGroupSlice{o}) + case bob.QueryTypeDelete: + ctx, err = AuthGroups.AfterDeleteHooks.RunHooks(ctx, exec, AuthGroupSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the AuthGroup +func (o *AuthGroup) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *AuthGroup) pkEQ() dialect.Expression { + return mysql.Quote("auth_group", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the AuthGroup +func (o *AuthGroup) Update(ctx context.Context, exec bob.Executor, s *AuthGroupSetter) error { + _, err := AuthGroups.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single AuthGroup record with an executor +func (o *AuthGroup) Delete(ctx context.Context, exec bob.Executor) error { + _, err := AuthGroups.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the AuthGroup using the executor +func (o *AuthGroup) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := AuthGroups.Query( + sm.Where(AuthGroups.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after AuthGroupSlice is retrieved from the database +func (o AuthGroupSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthGroups.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = AuthGroups.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = AuthGroups.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = AuthGroups.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o AuthGroupSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("auth_group", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o AuthGroupSlice) copyMatchingRows(from ...*AuthGroup) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o AuthGroupSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthGroups.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthGroup: + o.copyMatchingRows(retrieved) + case []*AuthGroup: + o.copyMatchingRows(retrieved...) + case AuthGroupSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthGroup or a slice of AuthGroup + // then run the AfterUpdateHooks on the slice + _, err = AuthGroups.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o AuthGroupSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthGroups.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthGroup: + o.copyMatchingRows(retrieved) + case []*AuthGroup: + o.copyMatchingRows(retrieved...) + case AuthGroupSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthGroup or a slice of AuthGroup + // then run the AfterDeleteHooks on the slice + _, err = AuthGroups.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o AuthGroupSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals AuthGroupSetter) error { + _, err := AuthGroups.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o AuthGroupSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := AuthGroups.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o AuthGroupSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := AuthGroups.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// GroupAuthGroupPermissions starts a query for related objects on auth_group_permissions +func (o *AuthGroup) GroupAuthGroupPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthGroupPermissionsQuery { + return AuthGroupPermissions.Query(append(mods, + sm.Where(AuthGroupPermissions.Columns.GroupID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthGroupSlice) GroupAuthGroupPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthGroupPermissionsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthGroupPermissions.Query(append(mods, + sm.Where(mysql.Group(AuthGroupPermissions.Columns.GroupID).OP("IN", PKArgExpr)), + )...) +} + +// GroupAuthUserGroups starts a query for related objects on auth_user_groups +func (o *AuthGroup) GroupAuthUserGroups(mods ...bob.Mod[*dialect.SelectQuery]) AuthUserGroupsQuery { + return AuthUserGroups.Query(append(mods, + sm.Where(AuthUserGroups.Columns.GroupID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthGroupSlice) GroupAuthUserGroups(mods ...bob.Mod[*dialect.SelectQuery]) AuthUserGroupsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUserGroups.Query(append(mods, + sm.Where(mysql.Group(AuthUserGroups.Columns.GroupID).OP("IN", PKArgExpr)), + )...) +} + +func insertAuthGroupGroupAuthGroupPermissions0(ctx context.Context, exec bob.Executor, authGroupPermissions1 []*AuthGroupPermissionSetter, authGroup0 *AuthGroup) (AuthGroupPermissionSlice, error) { + for i := range authGroupPermissions1 { + authGroupPermissions1[i].GroupID = omit.From(authGroup0.ID) + } + + ret, err := AuthGroupPermissions.Insert(bob.ToMods(authGroupPermissions1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthGroupGroupAuthGroupPermissions0: %w", err) + } + + return ret, nil +} + +func attachAuthGroupGroupAuthGroupPermissions0(ctx context.Context, exec bob.Executor, count int, authGroupPermissions1 AuthGroupPermissionSlice, authGroup0 *AuthGroup) (AuthGroupPermissionSlice, error) { + setter := &AuthGroupPermissionSetter{ + GroupID: omit.From(authGroup0.ID), + } + + err := authGroupPermissions1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAuthGroupGroupAuthGroupPermissions0: %w", err) + } + + return authGroupPermissions1, nil +} + +func (authGroup0 *AuthGroup) InsertGroupAuthGroupPermissions(ctx context.Context, exec bob.Executor, related ...*AuthGroupPermissionSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + authGroupPermissions1, err := insertAuthGroupGroupAuthGroupPermissions0(ctx, exec, related, authGroup0) + if err != nil { + return err + } + + authGroup0.R.GroupAuthGroupPermissions = append(authGroup0.R.GroupAuthGroupPermissions, authGroupPermissions1...) + + for _, rel := range authGroupPermissions1 { + rel.R.GroupAuthGroup = authGroup0 + } + return nil +} + +func (authGroup0 *AuthGroup) AttachGroupAuthGroupPermissions(ctx context.Context, exec bob.Executor, related ...*AuthGroupPermission) error { + if len(related) == 0 { + return nil + } + + var err error + authGroupPermissions1 := AuthGroupPermissionSlice(related) + + _, err = attachAuthGroupGroupAuthGroupPermissions0(ctx, exec, len(related), authGroupPermissions1, authGroup0) + if err != nil { + return err + } + + authGroup0.R.GroupAuthGroupPermissions = append(authGroup0.R.GroupAuthGroupPermissions, authGroupPermissions1...) + + for _, rel := range related { + rel.R.GroupAuthGroup = authGroup0 + } + + return nil +} + +func insertAuthGroupGroupAuthUserGroups0(ctx context.Context, exec bob.Executor, authUserGroups1 []*AuthUserGroupSetter, authGroup0 *AuthGroup) (AuthUserGroupSlice, error) { + for i := range authUserGroups1 { + authUserGroups1[i].GroupID = omit.From(authGroup0.ID) + } + + ret, err := AuthUserGroups.Insert(bob.ToMods(authUserGroups1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthGroupGroupAuthUserGroups0: %w", err) + } + + return ret, nil +} + +func attachAuthGroupGroupAuthUserGroups0(ctx context.Context, exec bob.Executor, count int, authUserGroups1 AuthUserGroupSlice, authGroup0 *AuthGroup) (AuthUserGroupSlice, error) { + setter := &AuthUserGroupSetter{ + GroupID: omit.From(authGroup0.ID), + } + + err := authUserGroups1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAuthGroupGroupAuthUserGroups0: %w", err) + } + + return authUserGroups1, nil +} + +func (authGroup0 *AuthGroup) InsertGroupAuthUserGroups(ctx context.Context, exec bob.Executor, related ...*AuthUserGroupSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + authUserGroups1, err := insertAuthGroupGroupAuthUserGroups0(ctx, exec, related, authGroup0) + if err != nil { + return err + } + + authGroup0.R.GroupAuthUserGroups = append(authGroup0.R.GroupAuthUserGroups, authUserGroups1...) + + for _, rel := range authUserGroups1 { + rel.R.GroupAuthGroup = authGroup0 + } + return nil +} + +func (authGroup0 *AuthGroup) AttachGroupAuthUserGroups(ctx context.Context, exec bob.Executor, related ...*AuthUserGroup) error { + if len(related) == 0 { + return nil + } + + var err error + authUserGroups1 := AuthUserGroupSlice(related) + + _, err = attachAuthGroupGroupAuthUserGroups0(ctx, exec, len(related), authUserGroups1, authGroup0) + if err != nil { + return err + } + + authGroup0.R.GroupAuthUserGroups = append(authGroup0.R.GroupAuthUserGroups, authUserGroups1...) + + for _, rel := range related { + rel.R.GroupAuthGroup = authGroup0 + } + + return nil +} + +type authGroupWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Name mysql.WhereMod[Q, string] +} + +func (authGroupWhere[Q]) AliasedAs(alias string) authGroupWhere[Q] { + return buildAuthGroupWhere[Q](buildAuthGroupColumns(alias)) +} + +func buildAuthGroupWhere[Q mysql.Filterable](cols authGroupColumns) authGroupWhere[Q] { + return authGroupWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Name: mysql.Where[Q, string](cols.Name), + } +} + +func (o *AuthGroup) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "GroupAuthGroupPermissions": + rels, ok := retrieved.(AuthGroupPermissionSlice) + if !ok { + return fmt.Errorf("authGroup cannot load %T as %q", retrieved, name) + } + + o.R.GroupAuthGroupPermissions = rels + + for _, rel := range rels { + if rel != nil { + rel.R.GroupAuthGroup = o + } + } + return nil + case "GroupAuthUserGroups": + rels, ok := retrieved.(AuthUserGroupSlice) + if !ok { + return fmt.Errorf("authGroup cannot load %T as %q", retrieved, name) + } + + o.R.GroupAuthUserGroups = rels + + for _, rel := range rels { + if rel != nil { + rel.R.GroupAuthGroup = o + } + } + return nil + default: + return fmt.Errorf("authGroup has no relationship %q", name) + } +} + +type authGroupPreloader struct{} + +func buildAuthGroupPreloader() authGroupPreloader { + return authGroupPreloader{} +} + +type authGroupThenLoader[Q orm.Loadable] struct { + GroupAuthGroupPermissions func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + GroupAuthUserGroups func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildAuthGroupThenLoader[Q orm.Loadable]() authGroupThenLoader[Q] { + type GroupAuthGroupPermissionsLoadInterface interface { + LoadGroupAuthGroupPermissions(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type GroupAuthUserGroupsLoadInterface interface { + LoadGroupAuthUserGroups(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return authGroupThenLoader[Q]{ + GroupAuthGroupPermissions: thenLoadBuilder[Q]( + "GroupAuthGroupPermissions", + func(ctx context.Context, exec bob.Executor, retrieved GroupAuthGroupPermissionsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadGroupAuthGroupPermissions(ctx, exec, mods...) + }, + ), + GroupAuthUserGroups: thenLoadBuilder[Q]( + "GroupAuthUserGroups", + func(ctx context.Context, exec bob.Executor, retrieved GroupAuthUserGroupsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadGroupAuthUserGroups(ctx, exec, mods...) + }, + ), + } +} + +// LoadGroupAuthGroupPermissions loads the authGroup's GroupAuthGroupPermissions into the .R struct +func (o *AuthGroup) LoadGroupAuthGroupPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.GroupAuthGroupPermissions = nil + + related, err := o.GroupAuthGroupPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.GroupAuthGroup = o + } + + o.R.GroupAuthGroupPermissions = related + return nil +} + +// LoadGroupAuthGroupPermissions loads the authGroup's GroupAuthGroupPermissions into the .R struct +func (os AuthGroupSlice) LoadGroupAuthGroupPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authGroupPermissions, err := os.GroupAuthGroupPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.GroupAuthGroupPermissions = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authGroupPermissions { + + if !(o.ID == rel.GroupID) { + continue + } + + rel.R.GroupAuthGroup = o + + o.R.GroupAuthGroupPermissions = append(o.R.GroupAuthGroupPermissions, rel) + } + } + + return nil +} + +// LoadGroupAuthUserGroups loads the authGroup's GroupAuthUserGroups into the .R struct +func (o *AuthGroup) LoadGroupAuthUserGroups(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.GroupAuthUserGroups = nil + + related, err := o.GroupAuthUserGroups(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.GroupAuthGroup = o + } + + o.R.GroupAuthUserGroups = related + return nil +} + +// LoadGroupAuthUserGroups loads the authGroup's GroupAuthUserGroups into the .R struct +func (os AuthGroupSlice) LoadGroupAuthUserGroups(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUserGroups, err := os.GroupAuthUserGroups(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.GroupAuthUserGroups = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUserGroups { + + if !(o.ID == rel.GroupID) { + continue + } + + rel.R.GroupAuthGroup = o + + o.R.GroupAuthUserGroups = append(o.R.GroupAuthUserGroups, rel) + } + } + + return nil +} + +type authGroupJoins[Q dialect.Joinable] struct { + typ string + GroupAuthGroupPermissions modAs[Q, authGroupPermissionColumns] + GroupAuthUserGroups modAs[Q, authUserGroupColumns] +} + +func (j authGroupJoins[Q]) aliasedAs(alias string) authGroupJoins[Q] { + return buildAuthGroupJoins[Q](buildAuthGroupColumns(alias), j.typ) +} + +func buildAuthGroupJoins[Q dialect.Joinable](cols authGroupColumns, typ string) authGroupJoins[Q] { + return authGroupJoins[Q]{ + typ: typ, + GroupAuthGroupPermissions: modAs[Q, authGroupPermissionColumns]{ + c: AuthGroupPermissions.Columns, + f: func(to authGroupPermissionColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthGroupPermissions.Name().As(to.Alias())).On( + to.GroupID.EQ(cols.ID), + )) + } + + return mods + }, + }, + GroupAuthUserGroups: modAs[Q, authUserGroupColumns]{ + c: AuthUserGroups.Columns, + f: func(to authUserGroupColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUserGroups.Name().As(to.Alias())).On( + to.GroupID.EQ(cols.ID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/auth_group_permissions.bob.go b/database/mcp/models/auth_group_permissions.bob.go new file mode 100644 index 0000000..7e671b0 --- /dev/null +++ b/database/mcp/models/auth_group_permissions.bob.go @@ -0,0 +1,787 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// AuthGroupPermission is an object representing the database table. +type AuthGroupPermission struct { + ID int32 `db:"id,pk,autoincr" ` + GroupID int32 `db:"group_id" ` + PermissionID int32 `db:"permission_id" ` + + R authGroupPermissionR `db:"-" ` +} + +// AuthGroupPermissionSlice is an alias for a slice of pointers to AuthGroupPermission. +// This should almost always be used instead of []*AuthGroupPermission. +type AuthGroupPermissionSlice []*AuthGroupPermission + +// AuthGroupPermissions contains methods to work with the auth_group_permissions table +var AuthGroupPermissions = mysql.NewTablex[*AuthGroupPermission, AuthGroupPermissionSlice, *AuthGroupPermissionSetter]("auth_group_permissions", buildAuthGroupPermissionColumns("auth_group_permissions"), []string{"id"}, []string{"group_id", "permission_id"}) + +// AuthGroupPermissionsQuery is a query on the auth_group_permissions table +type AuthGroupPermissionsQuery = *mysql.ViewQuery[*AuthGroupPermission, AuthGroupPermissionSlice] + +// authGroupPermissionR is where relationships are stored. +type authGroupPermissionR struct { + PermissionAuthPermission *AuthPermission // auth_group_permissio_permission_id_84c5c92e_fk_auth_perm + GroupAuthGroup *AuthGroup // auth_group_permissions_group_id_b120cbf9_fk_auth_group_id +} + +func buildAuthGroupPermissionColumns(alias string) authGroupPermissionColumns { + return authGroupPermissionColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "group_id", "permission_id", + ).WithParent("auth_group_permissions"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + GroupID: mysql.Quote(alias, "group_id"), + PermissionID: mysql.Quote(alias, "permission_id"), + } +} + +type authGroupPermissionColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + GroupID mysql.Expression + PermissionID mysql.Expression +} + +func (c authGroupPermissionColumns) Alias() string { + return c.tableAlias +} + +func (authGroupPermissionColumns) AliasedAs(alias string) authGroupPermissionColumns { + return buildAuthGroupPermissionColumns(alias) +} + +// AuthGroupPermissionSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type AuthGroupPermissionSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + GroupID omit.Val[int32] `db:"group_id" ` + PermissionID omit.Val[int32] `db:"permission_id" ` +} + +func (s AuthGroupPermissionSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.GroupID.IsValue() { + vals = append(vals, "group_id") + } + if s.PermissionID.IsValue() { + vals = append(vals, "permission_id") + } + return vals +} + +func (s AuthGroupPermissionSetter) Overwrite(t *AuthGroupPermission) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.GroupID.IsValue() { + t.GroupID = s.GroupID.MustGet() + } + if s.PermissionID.IsValue() { + t.PermissionID = s.PermissionID.MustGet() + } +} + +func (s *AuthGroupPermissionSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthGroupPermissions.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.GroupID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.GroupID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.PermissionID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PermissionID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s AuthGroupPermissionSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("auth_group_permissions")...) +} + +func (s AuthGroupPermissionSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.GroupID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "group_id")...), + mysql.Arg(s.GroupID), + }}) + } + + if s.PermissionID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "permission_id")...), + mysql.Arg(s.PermissionID), + }}) + } + + return exprs +} + +// FindAuthGroupPermission retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindAuthGroupPermission(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*AuthGroupPermission, error) { + if len(cols) == 0 { + return AuthGroupPermissions.Query( + sm.Where(AuthGroupPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return AuthGroupPermissions.Query( + sm.Where(AuthGroupPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(AuthGroupPermissions.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// AuthGroupPermissionExists checks the presence of a single record by primary key +func AuthGroupPermissionExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return AuthGroupPermissions.Query( + sm.Where(AuthGroupPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after AuthGroupPermission is retrieved from the database +func (o *AuthGroupPermission) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthGroupPermissions.AfterSelectHooks.RunHooks(ctx, exec, AuthGroupPermissionSlice{o}) + case bob.QueryTypeInsert: + ctx, err = AuthGroupPermissions.AfterInsertHooks.RunHooks(ctx, exec, AuthGroupPermissionSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = AuthGroupPermissions.AfterUpdateHooks.RunHooks(ctx, exec, AuthGroupPermissionSlice{o}) + case bob.QueryTypeDelete: + ctx, err = AuthGroupPermissions.AfterDeleteHooks.RunHooks(ctx, exec, AuthGroupPermissionSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the AuthGroupPermission +func (o *AuthGroupPermission) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *AuthGroupPermission) pkEQ() dialect.Expression { + return mysql.Quote("auth_group_permissions", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the AuthGroupPermission +func (o *AuthGroupPermission) Update(ctx context.Context, exec bob.Executor, s *AuthGroupPermissionSetter) error { + _, err := AuthGroupPermissions.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single AuthGroupPermission record with an executor +func (o *AuthGroupPermission) Delete(ctx context.Context, exec bob.Executor) error { + _, err := AuthGroupPermissions.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the AuthGroupPermission using the executor +func (o *AuthGroupPermission) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := AuthGroupPermissions.Query( + sm.Where(AuthGroupPermissions.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after AuthGroupPermissionSlice is retrieved from the database +func (o AuthGroupPermissionSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthGroupPermissions.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = AuthGroupPermissions.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = AuthGroupPermissions.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = AuthGroupPermissions.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o AuthGroupPermissionSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("auth_group_permissions", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o AuthGroupPermissionSlice) copyMatchingRows(from ...*AuthGroupPermission) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o AuthGroupPermissionSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthGroupPermissions.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthGroupPermission: + o.copyMatchingRows(retrieved) + case []*AuthGroupPermission: + o.copyMatchingRows(retrieved...) + case AuthGroupPermissionSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthGroupPermission or a slice of AuthGroupPermission + // then run the AfterUpdateHooks on the slice + _, err = AuthGroupPermissions.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o AuthGroupPermissionSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthGroupPermissions.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthGroupPermission: + o.copyMatchingRows(retrieved) + case []*AuthGroupPermission: + o.copyMatchingRows(retrieved...) + case AuthGroupPermissionSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthGroupPermission or a slice of AuthGroupPermission + // then run the AfterDeleteHooks on the slice + _, err = AuthGroupPermissions.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o AuthGroupPermissionSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals AuthGroupPermissionSetter) error { + _, err := AuthGroupPermissions.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o AuthGroupPermissionSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := AuthGroupPermissions.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o AuthGroupPermissionSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := AuthGroupPermissions.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// PermissionAuthPermission starts a query for related objects on auth_permission +func (o *AuthGroupPermission) PermissionAuthPermission(mods ...bob.Mod[*dialect.SelectQuery]) AuthPermissionsQuery { + return AuthPermissions.Query(append(mods, + sm.Where(AuthPermissions.Columns.ID.EQ(mysql.Arg(o.PermissionID))), + )...) +} + +func (os AuthGroupPermissionSlice) PermissionAuthPermission(mods ...bob.Mod[*dialect.SelectQuery]) AuthPermissionsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PermissionID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthPermissions.Query(append(mods, + sm.Where(mysql.Group(AuthPermissions.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// GroupAuthGroup starts a query for related objects on auth_group +func (o *AuthGroupPermission) GroupAuthGroup(mods ...bob.Mod[*dialect.SelectQuery]) AuthGroupsQuery { + return AuthGroups.Query(append(mods, + sm.Where(AuthGroups.Columns.ID.EQ(mysql.Arg(o.GroupID))), + )...) +} + +func (os AuthGroupPermissionSlice) GroupAuthGroup(mods ...bob.Mod[*dialect.SelectQuery]) AuthGroupsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.GroupID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthGroups.Query(append(mods, + sm.Where(mysql.Group(AuthGroups.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func attachAuthGroupPermissionPermissionAuthPermission0(ctx context.Context, exec bob.Executor, count int, authGroupPermission0 *AuthGroupPermission, authPermission1 *AuthPermission) (*AuthGroupPermission, error) { + setter := &AuthGroupPermissionSetter{ + PermissionID: omit.From(authPermission1.ID), + } + + err := authGroupPermission0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachAuthGroupPermissionPermissionAuthPermission0: %w", err) + } + + return authGroupPermission0, nil +} + +func (authGroupPermission0 *AuthGroupPermission) InsertPermissionAuthPermission(ctx context.Context, exec bob.Executor, related *AuthPermissionSetter) error { + var err error + + authPermission1, err := AuthPermissions.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachAuthGroupPermissionPermissionAuthPermission0(ctx, exec, 1, authGroupPermission0, authPermission1) + if err != nil { + return err + } + + authGroupPermission0.R.PermissionAuthPermission = authPermission1 + + authPermission1.R.PermissionAuthGroupPermissions = append(authPermission1.R.PermissionAuthGroupPermissions, authGroupPermission0) + + return nil +} + +func (authGroupPermission0 *AuthGroupPermission) AttachPermissionAuthPermission(ctx context.Context, exec bob.Executor, authPermission1 *AuthPermission) error { + var err error + + _, err = attachAuthGroupPermissionPermissionAuthPermission0(ctx, exec, 1, authGroupPermission0, authPermission1) + if err != nil { + return err + } + + authGroupPermission0.R.PermissionAuthPermission = authPermission1 + + authPermission1.R.PermissionAuthGroupPermissions = append(authPermission1.R.PermissionAuthGroupPermissions, authGroupPermission0) + + return nil +} + +func attachAuthGroupPermissionGroupAuthGroup0(ctx context.Context, exec bob.Executor, count int, authGroupPermission0 *AuthGroupPermission, authGroup1 *AuthGroup) (*AuthGroupPermission, error) { + setter := &AuthGroupPermissionSetter{ + GroupID: omit.From(authGroup1.ID), + } + + err := authGroupPermission0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachAuthGroupPermissionGroupAuthGroup0: %w", err) + } + + return authGroupPermission0, nil +} + +func (authGroupPermission0 *AuthGroupPermission) InsertGroupAuthGroup(ctx context.Context, exec bob.Executor, related *AuthGroupSetter) error { + var err error + + authGroup1, err := AuthGroups.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachAuthGroupPermissionGroupAuthGroup0(ctx, exec, 1, authGroupPermission0, authGroup1) + if err != nil { + return err + } + + authGroupPermission0.R.GroupAuthGroup = authGroup1 + + authGroup1.R.GroupAuthGroupPermissions = append(authGroup1.R.GroupAuthGroupPermissions, authGroupPermission0) + + return nil +} + +func (authGroupPermission0 *AuthGroupPermission) AttachGroupAuthGroup(ctx context.Context, exec bob.Executor, authGroup1 *AuthGroup) error { + var err error + + _, err = attachAuthGroupPermissionGroupAuthGroup0(ctx, exec, 1, authGroupPermission0, authGroup1) + if err != nil { + return err + } + + authGroupPermission0.R.GroupAuthGroup = authGroup1 + + authGroup1.R.GroupAuthGroupPermissions = append(authGroup1.R.GroupAuthGroupPermissions, authGroupPermission0) + + return nil +} + +type authGroupPermissionWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + GroupID mysql.WhereMod[Q, int32] + PermissionID mysql.WhereMod[Q, int32] +} + +func (authGroupPermissionWhere[Q]) AliasedAs(alias string) authGroupPermissionWhere[Q] { + return buildAuthGroupPermissionWhere[Q](buildAuthGroupPermissionColumns(alias)) +} + +func buildAuthGroupPermissionWhere[Q mysql.Filterable](cols authGroupPermissionColumns) authGroupPermissionWhere[Q] { + return authGroupPermissionWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + GroupID: mysql.Where[Q, int32](cols.GroupID), + PermissionID: mysql.Where[Q, int32](cols.PermissionID), + } +} + +func (o *AuthGroupPermission) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "PermissionAuthPermission": + rel, ok := retrieved.(*AuthPermission) + if !ok { + return fmt.Errorf("authGroupPermission cannot load %T as %q", retrieved, name) + } + + o.R.PermissionAuthPermission = rel + + if rel != nil { + rel.R.PermissionAuthGroupPermissions = AuthGroupPermissionSlice{o} + } + return nil + case "GroupAuthGroup": + rel, ok := retrieved.(*AuthGroup) + if !ok { + return fmt.Errorf("authGroupPermission cannot load %T as %q", retrieved, name) + } + + o.R.GroupAuthGroup = rel + + if rel != nil { + rel.R.GroupAuthGroupPermissions = AuthGroupPermissionSlice{o} + } + return nil + default: + return fmt.Errorf("authGroupPermission has no relationship %q", name) + } +} + +type authGroupPermissionPreloader struct { + PermissionAuthPermission func(...mysql.PreloadOption) mysql.Preloader + GroupAuthGroup func(...mysql.PreloadOption) mysql.Preloader +} + +func buildAuthGroupPermissionPreloader() authGroupPermissionPreloader { + return authGroupPermissionPreloader{ + PermissionAuthPermission: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthPermission, AuthPermissionSlice](mysql.PreloadRel{ + Name: "PermissionAuthPermission", + Sides: []mysql.PreloadSide{ + { + From: AuthGroupPermissions, + To: AuthPermissions, + FromColumns: []string{"permission_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthPermissions.Columns.Names(), opts...) + }, + GroupAuthGroup: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthGroup, AuthGroupSlice](mysql.PreloadRel{ + Name: "GroupAuthGroup", + Sides: []mysql.PreloadSide{ + { + From: AuthGroupPermissions, + To: AuthGroups, + FromColumns: []string{"group_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthGroups.Columns.Names(), opts...) + }, + } +} + +type authGroupPermissionThenLoader[Q orm.Loadable] struct { + PermissionAuthPermission func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + GroupAuthGroup func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildAuthGroupPermissionThenLoader[Q orm.Loadable]() authGroupPermissionThenLoader[Q] { + type PermissionAuthPermissionLoadInterface interface { + LoadPermissionAuthPermission(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type GroupAuthGroupLoadInterface interface { + LoadGroupAuthGroup(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return authGroupPermissionThenLoader[Q]{ + PermissionAuthPermission: thenLoadBuilder[Q]( + "PermissionAuthPermission", + func(ctx context.Context, exec bob.Executor, retrieved PermissionAuthPermissionLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPermissionAuthPermission(ctx, exec, mods...) + }, + ), + GroupAuthGroup: thenLoadBuilder[Q]( + "GroupAuthGroup", + func(ctx context.Context, exec bob.Executor, retrieved GroupAuthGroupLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadGroupAuthGroup(ctx, exec, mods...) + }, + ), + } +} + +// LoadPermissionAuthPermission loads the authGroupPermission's PermissionAuthPermission into the .R struct +func (o *AuthGroupPermission) LoadPermissionAuthPermission(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PermissionAuthPermission = nil + + related, err := o.PermissionAuthPermission(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PermissionAuthGroupPermissions = AuthGroupPermissionSlice{o} + + o.R.PermissionAuthPermission = related + return nil +} + +// LoadPermissionAuthPermission loads the authGroupPermission's PermissionAuthPermission into the .R struct +func (os AuthGroupPermissionSlice) LoadPermissionAuthPermission(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authPermissions, err := os.PermissionAuthPermission(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authPermissions { + + if !(o.PermissionID == rel.ID) { + continue + } + + rel.R.PermissionAuthGroupPermissions = append(rel.R.PermissionAuthGroupPermissions, o) + + o.R.PermissionAuthPermission = rel + break + } + } + + return nil +} + +// LoadGroupAuthGroup loads the authGroupPermission's GroupAuthGroup into the .R struct +func (o *AuthGroupPermission) LoadGroupAuthGroup(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.GroupAuthGroup = nil + + related, err := o.GroupAuthGroup(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.GroupAuthGroupPermissions = AuthGroupPermissionSlice{o} + + o.R.GroupAuthGroup = related + return nil +} + +// LoadGroupAuthGroup loads the authGroupPermission's GroupAuthGroup into the .R struct +func (os AuthGroupPermissionSlice) LoadGroupAuthGroup(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authGroups, err := os.GroupAuthGroup(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authGroups { + + if !(o.GroupID == rel.ID) { + continue + } + + rel.R.GroupAuthGroupPermissions = append(rel.R.GroupAuthGroupPermissions, o) + + o.R.GroupAuthGroup = rel + break + } + } + + return nil +} + +type authGroupPermissionJoins[Q dialect.Joinable] struct { + typ string + PermissionAuthPermission modAs[Q, authPermissionColumns] + GroupAuthGroup modAs[Q, authGroupColumns] +} + +func (j authGroupPermissionJoins[Q]) aliasedAs(alias string) authGroupPermissionJoins[Q] { + return buildAuthGroupPermissionJoins[Q](buildAuthGroupPermissionColumns(alias), j.typ) +} + +func buildAuthGroupPermissionJoins[Q dialect.Joinable](cols authGroupPermissionColumns, typ string) authGroupPermissionJoins[Q] { + return authGroupPermissionJoins[Q]{ + typ: typ, + PermissionAuthPermission: modAs[Q, authPermissionColumns]{ + c: AuthPermissions.Columns, + f: func(to authPermissionColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthPermissions.Name().As(to.Alias())).On( + to.ID.EQ(cols.PermissionID), + )) + } + + return mods + }, + }, + GroupAuthGroup: modAs[Q, authGroupColumns]{ + c: AuthGroups.Columns, + f: func(to authGroupColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthGroups.Name().As(to.Alias())).On( + to.ID.EQ(cols.GroupID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/auth_permission.bob.go b/database/mcp/models/auth_permission.bob.go new file mode 100644 index 0000000..fff655a --- /dev/null +++ b/database/mcp/models/auth_permission.bob.go @@ -0,0 +1,1016 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// AuthPermission is an object representing the database table. +type AuthPermission struct { + ID int32 `db:"id,pk,autoincr" ` + Name string `db:"name" ` + ContentTypeID int32 `db:"content_type_id" ` + Codename string `db:"codename" ` + + R authPermissionR `db:"-" ` +} + +// AuthPermissionSlice is an alias for a slice of pointers to AuthPermission. +// This should almost always be used instead of []*AuthPermission. +type AuthPermissionSlice []*AuthPermission + +// AuthPermissions contains methods to work with the auth_permission table +var AuthPermissions = mysql.NewTablex[*AuthPermission, AuthPermissionSlice, *AuthPermissionSetter]("auth_permission", buildAuthPermissionColumns("auth_permission"), []string{"id"}, []string{"content_type_id", "codename"}) + +// AuthPermissionsQuery is a query on the auth_permission table +type AuthPermissionsQuery = *mysql.ViewQuery[*AuthPermission, AuthPermissionSlice] + +// authPermissionR is where relationships are stored. +type authPermissionR struct { + PermissionAuthGroupPermissions AuthGroupPermissionSlice // auth_group_permissio_permission_id_84c5c92e_fk_auth_perm + ContentTypeDjangoContentType *DjangoContentType // auth_permission_content_type_id_2f476e4b_fk_django_co + PermissionAuthUserUserPermissions AuthUserUserPermissionSlice // auth_user_user_permi_permission_id_1fbb5f2c_fk_auth_perm +} + +func buildAuthPermissionColumns(alias string) authPermissionColumns { + return authPermissionColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "name", "content_type_id", "codename", + ).WithParent("auth_permission"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Name: mysql.Quote(alias, "name"), + ContentTypeID: mysql.Quote(alias, "content_type_id"), + Codename: mysql.Quote(alias, "codename"), + } +} + +type authPermissionColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Name mysql.Expression + ContentTypeID mysql.Expression + Codename mysql.Expression +} + +func (c authPermissionColumns) Alias() string { + return c.tableAlias +} + +func (authPermissionColumns) AliasedAs(alias string) authPermissionColumns { + return buildAuthPermissionColumns(alias) +} + +// AuthPermissionSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type AuthPermissionSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Name omit.Val[string] `db:"name" ` + ContentTypeID omit.Val[int32] `db:"content_type_id" ` + Codename omit.Val[string] `db:"codename" ` +} + +func (s AuthPermissionSetter) SetColumns() []string { + vals := make([]string, 0, 4) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Name.IsValue() { + vals = append(vals, "name") + } + if s.ContentTypeID.IsValue() { + vals = append(vals, "content_type_id") + } + if s.Codename.IsValue() { + vals = append(vals, "codename") + } + return vals +} + +func (s AuthPermissionSetter) Overwrite(t *AuthPermission) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Name.IsValue() { + t.Name = s.Name.MustGet() + } + if s.ContentTypeID.IsValue() { + t.ContentTypeID = s.ContentTypeID.MustGet() + } + if s.Codename.IsValue() { + t.Codename = s.Codename.MustGet() + } +} + +func (s *AuthPermissionSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthPermissions.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Name.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Name.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ContentTypeID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ContentTypeID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Codename.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Codename.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s AuthPermissionSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("auth_permission")...) +} + +func (s AuthPermissionSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 4) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Name.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "name")...), + mysql.Arg(s.Name), + }}) + } + + if s.ContentTypeID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "content_type_id")...), + mysql.Arg(s.ContentTypeID), + }}) + } + + if s.Codename.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "codename")...), + mysql.Arg(s.Codename), + }}) + } + + return exprs +} + +// FindAuthPermission retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindAuthPermission(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*AuthPermission, error) { + if len(cols) == 0 { + return AuthPermissions.Query( + sm.Where(AuthPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return AuthPermissions.Query( + sm.Where(AuthPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(AuthPermissions.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// AuthPermissionExists checks the presence of a single record by primary key +func AuthPermissionExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return AuthPermissions.Query( + sm.Where(AuthPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after AuthPermission is retrieved from the database +func (o *AuthPermission) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthPermissions.AfterSelectHooks.RunHooks(ctx, exec, AuthPermissionSlice{o}) + case bob.QueryTypeInsert: + ctx, err = AuthPermissions.AfterInsertHooks.RunHooks(ctx, exec, AuthPermissionSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = AuthPermissions.AfterUpdateHooks.RunHooks(ctx, exec, AuthPermissionSlice{o}) + case bob.QueryTypeDelete: + ctx, err = AuthPermissions.AfterDeleteHooks.RunHooks(ctx, exec, AuthPermissionSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the AuthPermission +func (o *AuthPermission) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *AuthPermission) pkEQ() dialect.Expression { + return mysql.Quote("auth_permission", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the AuthPermission +func (o *AuthPermission) Update(ctx context.Context, exec bob.Executor, s *AuthPermissionSetter) error { + _, err := AuthPermissions.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single AuthPermission record with an executor +func (o *AuthPermission) Delete(ctx context.Context, exec bob.Executor) error { + _, err := AuthPermissions.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the AuthPermission using the executor +func (o *AuthPermission) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := AuthPermissions.Query( + sm.Where(AuthPermissions.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after AuthPermissionSlice is retrieved from the database +func (o AuthPermissionSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthPermissions.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = AuthPermissions.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = AuthPermissions.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = AuthPermissions.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o AuthPermissionSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("auth_permission", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o AuthPermissionSlice) copyMatchingRows(from ...*AuthPermission) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o AuthPermissionSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthPermissions.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthPermission: + o.copyMatchingRows(retrieved) + case []*AuthPermission: + o.copyMatchingRows(retrieved...) + case AuthPermissionSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthPermission or a slice of AuthPermission + // then run the AfterUpdateHooks on the slice + _, err = AuthPermissions.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o AuthPermissionSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthPermissions.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthPermission: + o.copyMatchingRows(retrieved) + case []*AuthPermission: + o.copyMatchingRows(retrieved...) + case AuthPermissionSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthPermission or a slice of AuthPermission + // then run the AfterDeleteHooks on the slice + _, err = AuthPermissions.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o AuthPermissionSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals AuthPermissionSetter) error { + _, err := AuthPermissions.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o AuthPermissionSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := AuthPermissions.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o AuthPermissionSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := AuthPermissions.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// PermissionAuthGroupPermissions starts a query for related objects on auth_group_permissions +func (o *AuthPermission) PermissionAuthGroupPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthGroupPermissionsQuery { + return AuthGroupPermissions.Query(append(mods, + sm.Where(AuthGroupPermissions.Columns.PermissionID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthPermissionSlice) PermissionAuthGroupPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthGroupPermissionsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthGroupPermissions.Query(append(mods, + sm.Where(mysql.Group(AuthGroupPermissions.Columns.PermissionID).OP("IN", PKArgExpr)), + )...) +} + +// ContentTypeDjangoContentType starts a query for related objects on django_content_type +func (o *AuthPermission) ContentTypeDjangoContentType(mods ...bob.Mod[*dialect.SelectQuery]) DjangoContentTypesQuery { + return DjangoContentTypes.Query(append(mods, + sm.Where(DjangoContentTypes.Columns.ID.EQ(mysql.Arg(o.ContentTypeID))), + )...) +} + +func (os AuthPermissionSlice) ContentTypeDjangoContentType(mods ...bob.Mod[*dialect.SelectQuery]) DjangoContentTypesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ContentTypeID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return DjangoContentTypes.Query(append(mods, + sm.Where(mysql.Group(DjangoContentTypes.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// PermissionAuthUserUserPermissions starts a query for related objects on auth_user_user_permissions +func (o *AuthPermission) PermissionAuthUserUserPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthUserUserPermissionsQuery { + return AuthUserUserPermissions.Query(append(mods, + sm.Where(AuthUserUserPermissions.Columns.PermissionID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthPermissionSlice) PermissionAuthUserUserPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthUserUserPermissionsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUserUserPermissions.Query(append(mods, + sm.Where(mysql.Group(AuthUserUserPermissions.Columns.PermissionID).OP("IN", PKArgExpr)), + )...) +} + +func insertAuthPermissionPermissionAuthGroupPermissions0(ctx context.Context, exec bob.Executor, authGroupPermissions1 []*AuthGroupPermissionSetter, authPermission0 *AuthPermission) (AuthGroupPermissionSlice, error) { + for i := range authGroupPermissions1 { + authGroupPermissions1[i].PermissionID = omit.From(authPermission0.ID) + } + + ret, err := AuthGroupPermissions.Insert(bob.ToMods(authGroupPermissions1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthPermissionPermissionAuthGroupPermissions0: %w", err) + } + + return ret, nil +} + +func attachAuthPermissionPermissionAuthGroupPermissions0(ctx context.Context, exec bob.Executor, count int, authGroupPermissions1 AuthGroupPermissionSlice, authPermission0 *AuthPermission) (AuthGroupPermissionSlice, error) { + setter := &AuthGroupPermissionSetter{ + PermissionID: omit.From(authPermission0.ID), + } + + err := authGroupPermissions1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAuthPermissionPermissionAuthGroupPermissions0: %w", err) + } + + return authGroupPermissions1, nil +} + +func (authPermission0 *AuthPermission) InsertPermissionAuthGroupPermissions(ctx context.Context, exec bob.Executor, related ...*AuthGroupPermissionSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + authGroupPermissions1, err := insertAuthPermissionPermissionAuthGroupPermissions0(ctx, exec, related, authPermission0) + if err != nil { + return err + } + + authPermission0.R.PermissionAuthGroupPermissions = append(authPermission0.R.PermissionAuthGroupPermissions, authGroupPermissions1...) + + for _, rel := range authGroupPermissions1 { + rel.R.PermissionAuthPermission = authPermission0 + } + return nil +} + +func (authPermission0 *AuthPermission) AttachPermissionAuthGroupPermissions(ctx context.Context, exec bob.Executor, related ...*AuthGroupPermission) error { + if len(related) == 0 { + return nil + } + + var err error + authGroupPermissions1 := AuthGroupPermissionSlice(related) + + _, err = attachAuthPermissionPermissionAuthGroupPermissions0(ctx, exec, len(related), authGroupPermissions1, authPermission0) + if err != nil { + return err + } + + authPermission0.R.PermissionAuthGroupPermissions = append(authPermission0.R.PermissionAuthGroupPermissions, authGroupPermissions1...) + + for _, rel := range related { + rel.R.PermissionAuthPermission = authPermission0 + } + + return nil +} + +func attachAuthPermissionContentTypeDjangoContentType0(ctx context.Context, exec bob.Executor, count int, authPermission0 *AuthPermission, djangoContentType1 *DjangoContentType) (*AuthPermission, error) { + setter := &AuthPermissionSetter{ + ContentTypeID: omit.From(djangoContentType1.ID), + } + + err := authPermission0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachAuthPermissionContentTypeDjangoContentType0: %w", err) + } + + return authPermission0, nil +} + +func (authPermission0 *AuthPermission) InsertContentTypeDjangoContentType(ctx context.Context, exec bob.Executor, related *DjangoContentTypeSetter) error { + var err error + + djangoContentType1, err := DjangoContentTypes.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachAuthPermissionContentTypeDjangoContentType0(ctx, exec, 1, authPermission0, djangoContentType1) + if err != nil { + return err + } + + authPermission0.R.ContentTypeDjangoContentType = djangoContentType1 + + djangoContentType1.R.ContentTypeAuthPermissions = append(djangoContentType1.R.ContentTypeAuthPermissions, authPermission0) + + return nil +} + +func (authPermission0 *AuthPermission) AttachContentTypeDjangoContentType(ctx context.Context, exec bob.Executor, djangoContentType1 *DjangoContentType) error { + var err error + + _, err = attachAuthPermissionContentTypeDjangoContentType0(ctx, exec, 1, authPermission0, djangoContentType1) + if err != nil { + return err + } + + authPermission0.R.ContentTypeDjangoContentType = djangoContentType1 + + djangoContentType1.R.ContentTypeAuthPermissions = append(djangoContentType1.R.ContentTypeAuthPermissions, authPermission0) + + return nil +} + +func insertAuthPermissionPermissionAuthUserUserPermissions0(ctx context.Context, exec bob.Executor, authUserUserPermissions1 []*AuthUserUserPermissionSetter, authPermission0 *AuthPermission) (AuthUserUserPermissionSlice, error) { + for i := range authUserUserPermissions1 { + authUserUserPermissions1[i].PermissionID = omit.From(authPermission0.ID) + } + + ret, err := AuthUserUserPermissions.Insert(bob.ToMods(authUserUserPermissions1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthPermissionPermissionAuthUserUserPermissions0: %w", err) + } + + return ret, nil +} + +func attachAuthPermissionPermissionAuthUserUserPermissions0(ctx context.Context, exec bob.Executor, count int, authUserUserPermissions1 AuthUserUserPermissionSlice, authPermission0 *AuthPermission) (AuthUserUserPermissionSlice, error) { + setter := &AuthUserUserPermissionSetter{ + PermissionID: omit.From(authPermission0.ID), + } + + err := authUserUserPermissions1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAuthPermissionPermissionAuthUserUserPermissions0: %w", err) + } + + return authUserUserPermissions1, nil +} + +func (authPermission0 *AuthPermission) InsertPermissionAuthUserUserPermissions(ctx context.Context, exec bob.Executor, related ...*AuthUserUserPermissionSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + authUserUserPermissions1, err := insertAuthPermissionPermissionAuthUserUserPermissions0(ctx, exec, related, authPermission0) + if err != nil { + return err + } + + authPermission0.R.PermissionAuthUserUserPermissions = append(authPermission0.R.PermissionAuthUserUserPermissions, authUserUserPermissions1...) + + for _, rel := range authUserUserPermissions1 { + rel.R.PermissionAuthPermission = authPermission0 + } + return nil +} + +func (authPermission0 *AuthPermission) AttachPermissionAuthUserUserPermissions(ctx context.Context, exec bob.Executor, related ...*AuthUserUserPermission) error { + if len(related) == 0 { + return nil + } + + var err error + authUserUserPermissions1 := AuthUserUserPermissionSlice(related) + + _, err = attachAuthPermissionPermissionAuthUserUserPermissions0(ctx, exec, len(related), authUserUserPermissions1, authPermission0) + if err != nil { + return err + } + + authPermission0.R.PermissionAuthUserUserPermissions = append(authPermission0.R.PermissionAuthUserUserPermissions, authUserUserPermissions1...) + + for _, rel := range related { + rel.R.PermissionAuthPermission = authPermission0 + } + + return nil +} + +type authPermissionWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Name mysql.WhereMod[Q, string] + ContentTypeID mysql.WhereMod[Q, int32] + Codename mysql.WhereMod[Q, string] +} + +func (authPermissionWhere[Q]) AliasedAs(alias string) authPermissionWhere[Q] { + return buildAuthPermissionWhere[Q](buildAuthPermissionColumns(alias)) +} + +func buildAuthPermissionWhere[Q mysql.Filterable](cols authPermissionColumns) authPermissionWhere[Q] { + return authPermissionWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Name: mysql.Where[Q, string](cols.Name), + ContentTypeID: mysql.Where[Q, int32](cols.ContentTypeID), + Codename: mysql.Where[Q, string](cols.Codename), + } +} + +func (o *AuthPermission) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "PermissionAuthGroupPermissions": + rels, ok := retrieved.(AuthGroupPermissionSlice) + if !ok { + return fmt.Errorf("authPermission cannot load %T as %q", retrieved, name) + } + + o.R.PermissionAuthGroupPermissions = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PermissionAuthPermission = o + } + } + return nil + case "ContentTypeDjangoContentType": + rel, ok := retrieved.(*DjangoContentType) + if !ok { + return fmt.Errorf("authPermission cannot load %T as %q", retrieved, name) + } + + o.R.ContentTypeDjangoContentType = rel + + if rel != nil { + rel.R.ContentTypeAuthPermissions = AuthPermissionSlice{o} + } + return nil + case "PermissionAuthUserUserPermissions": + rels, ok := retrieved.(AuthUserUserPermissionSlice) + if !ok { + return fmt.Errorf("authPermission cannot load %T as %q", retrieved, name) + } + + o.R.PermissionAuthUserUserPermissions = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PermissionAuthPermission = o + } + } + return nil + default: + return fmt.Errorf("authPermission has no relationship %q", name) + } +} + +type authPermissionPreloader struct { + ContentTypeDjangoContentType func(...mysql.PreloadOption) mysql.Preloader +} + +func buildAuthPermissionPreloader() authPermissionPreloader { + return authPermissionPreloader{ + ContentTypeDjangoContentType: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*DjangoContentType, DjangoContentTypeSlice](mysql.PreloadRel{ + Name: "ContentTypeDjangoContentType", + Sides: []mysql.PreloadSide{ + { + From: AuthPermissions, + To: DjangoContentTypes, + FromColumns: []string{"content_type_id"}, + ToColumns: []string{"id"}, + }, + }, + }, DjangoContentTypes.Columns.Names(), opts...) + }, + } +} + +type authPermissionThenLoader[Q orm.Loadable] struct { + PermissionAuthGroupPermissions func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ContentTypeDjangoContentType func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PermissionAuthUserUserPermissions func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildAuthPermissionThenLoader[Q orm.Loadable]() authPermissionThenLoader[Q] { + type PermissionAuthGroupPermissionsLoadInterface interface { + LoadPermissionAuthGroupPermissions(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ContentTypeDjangoContentTypeLoadInterface interface { + LoadContentTypeDjangoContentType(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PermissionAuthUserUserPermissionsLoadInterface interface { + LoadPermissionAuthUserUserPermissions(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return authPermissionThenLoader[Q]{ + PermissionAuthGroupPermissions: thenLoadBuilder[Q]( + "PermissionAuthGroupPermissions", + func(ctx context.Context, exec bob.Executor, retrieved PermissionAuthGroupPermissionsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPermissionAuthGroupPermissions(ctx, exec, mods...) + }, + ), + ContentTypeDjangoContentType: thenLoadBuilder[Q]( + "ContentTypeDjangoContentType", + func(ctx context.Context, exec bob.Executor, retrieved ContentTypeDjangoContentTypeLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadContentTypeDjangoContentType(ctx, exec, mods...) + }, + ), + PermissionAuthUserUserPermissions: thenLoadBuilder[Q]( + "PermissionAuthUserUserPermissions", + func(ctx context.Context, exec bob.Executor, retrieved PermissionAuthUserUserPermissionsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPermissionAuthUserUserPermissions(ctx, exec, mods...) + }, + ), + } +} + +// LoadPermissionAuthGroupPermissions loads the authPermission's PermissionAuthGroupPermissions into the .R struct +func (o *AuthPermission) LoadPermissionAuthGroupPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PermissionAuthGroupPermissions = nil + + related, err := o.PermissionAuthGroupPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PermissionAuthPermission = o + } + + o.R.PermissionAuthGroupPermissions = related + return nil +} + +// LoadPermissionAuthGroupPermissions loads the authPermission's PermissionAuthGroupPermissions into the .R struct +func (os AuthPermissionSlice) LoadPermissionAuthGroupPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authGroupPermissions, err := os.PermissionAuthGroupPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PermissionAuthGroupPermissions = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authGroupPermissions { + + if !(o.ID == rel.PermissionID) { + continue + } + + rel.R.PermissionAuthPermission = o + + o.R.PermissionAuthGroupPermissions = append(o.R.PermissionAuthGroupPermissions, rel) + } + } + + return nil +} + +// LoadContentTypeDjangoContentType loads the authPermission's ContentTypeDjangoContentType into the .R struct +func (o *AuthPermission) LoadContentTypeDjangoContentType(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ContentTypeDjangoContentType = nil + + related, err := o.ContentTypeDjangoContentType(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.ContentTypeAuthPermissions = AuthPermissionSlice{o} + + o.R.ContentTypeDjangoContentType = related + return nil +} + +// LoadContentTypeDjangoContentType loads the authPermission's ContentTypeDjangoContentType into the .R struct +func (os AuthPermissionSlice) LoadContentTypeDjangoContentType(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + djangoContentTypes, err := os.ContentTypeDjangoContentType(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range djangoContentTypes { + + if !(o.ContentTypeID == rel.ID) { + continue + } + + rel.R.ContentTypeAuthPermissions = append(rel.R.ContentTypeAuthPermissions, o) + + o.R.ContentTypeDjangoContentType = rel + break + } + } + + return nil +} + +// LoadPermissionAuthUserUserPermissions loads the authPermission's PermissionAuthUserUserPermissions into the .R struct +func (o *AuthPermission) LoadPermissionAuthUserUserPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PermissionAuthUserUserPermissions = nil + + related, err := o.PermissionAuthUserUserPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PermissionAuthPermission = o + } + + o.R.PermissionAuthUserUserPermissions = related + return nil +} + +// LoadPermissionAuthUserUserPermissions loads the authPermission's PermissionAuthUserUserPermissions into the .R struct +func (os AuthPermissionSlice) LoadPermissionAuthUserUserPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUserUserPermissions, err := os.PermissionAuthUserUserPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PermissionAuthUserUserPermissions = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUserUserPermissions { + + if !(o.ID == rel.PermissionID) { + continue + } + + rel.R.PermissionAuthPermission = o + + o.R.PermissionAuthUserUserPermissions = append(o.R.PermissionAuthUserUserPermissions, rel) + } + } + + return nil +} + +type authPermissionJoins[Q dialect.Joinable] struct { + typ string + PermissionAuthGroupPermissions modAs[Q, authGroupPermissionColumns] + ContentTypeDjangoContentType modAs[Q, djangoContentTypeColumns] + PermissionAuthUserUserPermissions modAs[Q, authUserUserPermissionColumns] +} + +func (j authPermissionJoins[Q]) aliasedAs(alias string) authPermissionJoins[Q] { + return buildAuthPermissionJoins[Q](buildAuthPermissionColumns(alias), j.typ) +} + +func buildAuthPermissionJoins[Q dialect.Joinable](cols authPermissionColumns, typ string) authPermissionJoins[Q] { + return authPermissionJoins[Q]{ + typ: typ, + PermissionAuthGroupPermissions: modAs[Q, authGroupPermissionColumns]{ + c: AuthGroupPermissions.Columns, + f: func(to authGroupPermissionColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthGroupPermissions.Name().As(to.Alias())).On( + to.PermissionID.EQ(cols.ID), + )) + } + + return mods + }, + }, + ContentTypeDjangoContentType: modAs[Q, djangoContentTypeColumns]{ + c: DjangoContentTypes.Columns, + f: func(to djangoContentTypeColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, DjangoContentTypes.Name().As(to.Alias())).On( + to.ID.EQ(cols.ContentTypeID), + )) + } + + return mods + }, + }, + PermissionAuthUserUserPermissions: modAs[Q, authUserUserPermissionColumns]{ + c: AuthUserUserPermissions.Columns, + f: func(to authUserUserPermissionColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUserUserPermissions.Name().As(to.Alias())).On( + to.PermissionID.EQ(cols.ID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/auth_user.bob.go b/database/mcp/models/auth_user.bob.go new file mode 100644 index 0000000..bbe08d8 --- /dev/null +++ b/database/mcp/models/auth_user.bob.go @@ -0,0 +1,1572 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// AuthUser is an object representing the database table. +type AuthUser struct { + ID int32 `db:"id,pk,autoincr" ` + Password string `db:"password" ` + LastLogin null.Val[time.Time] `db:"last_login" ` + IsSuperuser bool `db:"is_superuser" ` + Username string `db:"username" ` + FirstName string `db:"first_name" ` + LastName string `db:"last_name" ` + Email string `db:"email" ` + IsStaff bool `db:"is_staff" ` + IsActive bool `db:"is_active" ` + DateJoined time.Time `db:"date_joined" ` + + R authUserR `db:"-" ` +} + +// AuthUserSlice is an alias for a slice of pointers to AuthUser. +// This should almost always be used instead of []*AuthUser. +type AuthUserSlice []*AuthUser + +// AuthUsers contains methods to work with the auth_user table +var AuthUsers = mysql.NewTablex[*AuthUser, AuthUserSlice, *AuthUserSetter]("auth_user", buildAuthUserColumns("auth_user"), []string{"id"}, []string{"username"}) + +// AuthUsersQuery is a query on the auth_user table +type AuthUsersQuery = *mysql.ViewQuery[*AuthUser, AuthUserSlice] + +// authUserR is where relationships are stored. +type authUserR struct { + UserAuthUserGroups AuthUserGroupSlice // auth_user_groups_user_id_6a12ed8b_fk_auth_user_id + UserAuthUserUserPermissions AuthUserUserPermissionSlice // auth_user_user_permissions_user_id_a95ead1b_fk_auth_user_id + UserDjangoAdminLogs DjangoAdminLogSlice // django_admin_log_user_id_c564eba6_fk_auth_user_id + AdminIDLocationsEvents LocationsEventSlice // locations_event_admin_id_id_4a50d36a_fk_auth_user_id + UserTastypieApikey *TastypieApikey // tastypie_apikey_user_id_8c8fa920_fk_auth_user_id +} + +func buildAuthUserColumns(alias string) authUserColumns { + return authUserColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "password", "last_login", "is_superuser", "username", "first_name", "last_name", "email", "is_staff", "is_active", "date_joined", + ).WithParent("auth_user"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Password: mysql.Quote(alias, "password"), + LastLogin: mysql.Quote(alias, "last_login"), + IsSuperuser: mysql.Quote(alias, "is_superuser"), + Username: mysql.Quote(alias, "username"), + FirstName: mysql.Quote(alias, "first_name"), + LastName: mysql.Quote(alias, "last_name"), + Email: mysql.Quote(alias, "email"), + IsStaff: mysql.Quote(alias, "is_staff"), + IsActive: mysql.Quote(alias, "is_active"), + DateJoined: mysql.Quote(alias, "date_joined"), + } +} + +type authUserColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Password mysql.Expression + LastLogin mysql.Expression + IsSuperuser mysql.Expression + Username mysql.Expression + FirstName mysql.Expression + LastName mysql.Expression + Email mysql.Expression + IsStaff mysql.Expression + IsActive mysql.Expression + DateJoined mysql.Expression +} + +func (c authUserColumns) Alias() string { + return c.tableAlias +} + +func (authUserColumns) AliasedAs(alias string) authUserColumns { + return buildAuthUserColumns(alias) +} + +// AuthUserSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type AuthUserSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Password omit.Val[string] `db:"password" ` + LastLogin omitnull.Val[time.Time] `db:"last_login" ` + IsSuperuser omit.Val[bool] `db:"is_superuser" ` + Username omit.Val[string] `db:"username" ` + FirstName omit.Val[string] `db:"first_name" ` + LastName omit.Val[string] `db:"last_name" ` + Email omit.Val[string] `db:"email" ` + IsStaff omit.Val[bool] `db:"is_staff" ` + IsActive omit.Val[bool] `db:"is_active" ` + DateJoined omit.Val[time.Time] `db:"date_joined" ` +} + +func (s AuthUserSetter) SetColumns() []string { + vals := make([]string, 0, 11) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Password.IsValue() { + vals = append(vals, "password") + } + if !s.LastLogin.IsUnset() { + vals = append(vals, "last_login") + } + if s.IsSuperuser.IsValue() { + vals = append(vals, "is_superuser") + } + if s.Username.IsValue() { + vals = append(vals, "username") + } + if s.FirstName.IsValue() { + vals = append(vals, "first_name") + } + if s.LastName.IsValue() { + vals = append(vals, "last_name") + } + if s.Email.IsValue() { + vals = append(vals, "email") + } + if s.IsStaff.IsValue() { + vals = append(vals, "is_staff") + } + if s.IsActive.IsValue() { + vals = append(vals, "is_active") + } + if s.DateJoined.IsValue() { + vals = append(vals, "date_joined") + } + return vals +} + +func (s AuthUserSetter) Overwrite(t *AuthUser) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Password.IsValue() { + t.Password = s.Password.MustGet() + } + if !s.LastLogin.IsUnset() { + t.LastLogin = s.LastLogin.MustGetNull() + } + if s.IsSuperuser.IsValue() { + t.IsSuperuser = s.IsSuperuser.MustGet() + } + if s.Username.IsValue() { + t.Username = s.Username.MustGet() + } + if s.FirstName.IsValue() { + t.FirstName = s.FirstName.MustGet() + } + if s.LastName.IsValue() { + t.LastName = s.LastName.MustGet() + } + if s.Email.IsValue() { + t.Email = s.Email.MustGet() + } + if s.IsStaff.IsValue() { + t.IsStaff = s.IsStaff.MustGet() + } + if s.IsActive.IsValue() { + t.IsActive = s.IsActive.MustGet() + } + if s.DateJoined.IsValue() { + t.DateJoined = s.DateJoined.MustGet() + } +} + +func (s *AuthUserSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUsers.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Password.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Password.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.LastLogin.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.LastLogin.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.IsSuperuser.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.IsSuperuser.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Username.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Username.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.FirstName.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.FirstName.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.LastName.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.LastName.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Email.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Email.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.IsStaff.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.IsStaff.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.IsActive.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.IsActive.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DateJoined.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DateJoined.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s AuthUserSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("auth_user")...) +} + +func (s AuthUserSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 11) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Password.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "password")...), + mysql.Arg(s.Password), + }}) + } + + if !s.LastLogin.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "last_login")...), + mysql.Arg(s.LastLogin), + }}) + } + + if s.IsSuperuser.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "is_superuser")...), + mysql.Arg(s.IsSuperuser), + }}) + } + + if s.Username.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "username")...), + mysql.Arg(s.Username), + }}) + } + + if s.FirstName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "first_name")...), + mysql.Arg(s.FirstName), + }}) + } + + if s.LastName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "last_name")...), + mysql.Arg(s.LastName), + }}) + } + + if s.Email.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "email")...), + mysql.Arg(s.Email), + }}) + } + + if s.IsStaff.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "is_staff")...), + mysql.Arg(s.IsStaff), + }}) + } + + if s.IsActive.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "is_active")...), + mysql.Arg(s.IsActive), + }}) + } + + if s.DateJoined.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "date_joined")...), + mysql.Arg(s.DateJoined), + }}) + } + + return exprs +} + +// FindAuthUser retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindAuthUser(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*AuthUser, error) { + if len(cols) == 0 { + return AuthUsers.Query( + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return AuthUsers.Query( + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(AuthUsers.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// AuthUserExists checks the presence of a single record by primary key +func AuthUserExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return AuthUsers.Query( + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after AuthUser is retrieved from the database +func (o *AuthUser) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthUsers.AfterSelectHooks.RunHooks(ctx, exec, AuthUserSlice{o}) + case bob.QueryTypeInsert: + ctx, err = AuthUsers.AfterInsertHooks.RunHooks(ctx, exec, AuthUserSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = AuthUsers.AfterUpdateHooks.RunHooks(ctx, exec, AuthUserSlice{o}) + case bob.QueryTypeDelete: + ctx, err = AuthUsers.AfterDeleteHooks.RunHooks(ctx, exec, AuthUserSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the AuthUser +func (o *AuthUser) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *AuthUser) pkEQ() dialect.Expression { + return mysql.Quote("auth_user", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the AuthUser +func (o *AuthUser) Update(ctx context.Context, exec bob.Executor, s *AuthUserSetter) error { + _, err := AuthUsers.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single AuthUser record with an executor +func (o *AuthUser) Delete(ctx context.Context, exec bob.Executor) error { + _, err := AuthUsers.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the AuthUser using the executor +func (o *AuthUser) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := AuthUsers.Query( + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after AuthUserSlice is retrieved from the database +func (o AuthUserSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthUsers.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = AuthUsers.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = AuthUsers.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = AuthUsers.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o AuthUserSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("auth_user", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o AuthUserSlice) copyMatchingRows(from ...*AuthUser) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o AuthUserSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUsers.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthUser: + o.copyMatchingRows(retrieved) + case []*AuthUser: + o.copyMatchingRows(retrieved...) + case AuthUserSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthUser or a slice of AuthUser + // then run the AfterUpdateHooks on the slice + _, err = AuthUsers.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o AuthUserSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUsers.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthUser: + o.copyMatchingRows(retrieved) + case []*AuthUser: + o.copyMatchingRows(retrieved...) + case AuthUserSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthUser or a slice of AuthUser + // then run the AfterDeleteHooks on the slice + _, err = AuthUsers.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o AuthUserSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals AuthUserSetter) error { + _, err := AuthUsers.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o AuthUserSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := AuthUsers.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o AuthUserSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := AuthUsers.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// UserAuthUserGroups starts a query for related objects on auth_user_groups +func (o *AuthUser) UserAuthUserGroups(mods ...bob.Mod[*dialect.SelectQuery]) AuthUserGroupsQuery { + return AuthUserGroups.Query(append(mods, + sm.Where(AuthUserGroups.Columns.UserID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthUserSlice) UserAuthUserGroups(mods ...bob.Mod[*dialect.SelectQuery]) AuthUserGroupsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUserGroups.Query(append(mods, + sm.Where(mysql.Group(AuthUserGroups.Columns.UserID).OP("IN", PKArgExpr)), + )...) +} + +// UserAuthUserUserPermissions starts a query for related objects on auth_user_user_permissions +func (o *AuthUser) UserAuthUserUserPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthUserUserPermissionsQuery { + return AuthUserUserPermissions.Query(append(mods, + sm.Where(AuthUserUserPermissions.Columns.UserID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthUserSlice) UserAuthUserUserPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthUserUserPermissionsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUserUserPermissions.Query(append(mods, + sm.Where(mysql.Group(AuthUserUserPermissions.Columns.UserID).OP("IN", PKArgExpr)), + )...) +} + +// UserDjangoAdminLogs starts a query for related objects on django_admin_log +func (o *AuthUser) UserDjangoAdminLogs(mods ...bob.Mod[*dialect.SelectQuery]) DjangoAdminLogsQuery { + return DjangoAdminLogs.Query(append(mods, + sm.Where(DjangoAdminLogs.Columns.UserID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthUserSlice) UserDjangoAdminLogs(mods ...bob.Mod[*dialect.SelectQuery]) DjangoAdminLogsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return DjangoAdminLogs.Query(append(mods, + sm.Where(mysql.Group(DjangoAdminLogs.Columns.UserID).OP("IN", PKArgExpr)), + )...) +} + +// AdminIDLocationsEvents starts a query for related objects on locations_event +func (o *AuthUser) AdminIDLocationsEvents(mods ...bob.Mod[*dialect.SelectQuery]) LocationsEventsQuery { + return LocationsEvents.Query(append(mods, + sm.Where(LocationsEvents.Columns.AdminIDID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthUserSlice) AdminIDLocationsEvents(mods ...bob.Mod[*dialect.SelectQuery]) LocationsEventsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsEvents.Query(append(mods, + sm.Where(mysql.Group(LocationsEvents.Columns.AdminIDID).OP("IN", PKArgExpr)), + )...) +} + +// UserTastypieApikey starts a query for related objects on tastypie_apikey +func (o *AuthUser) UserTastypieApikey(mods ...bob.Mod[*dialect.SelectQuery]) TastypieApikeysQuery { + return TastypieApikeys.Query(append(mods, + sm.Where(TastypieApikeys.Columns.UserID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthUserSlice) UserTastypieApikey(mods ...bob.Mod[*dialect.SelectQuery]) TastypieApikeysQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return TastypieApikeys.Query(append(mods, + sm.Where(mysql.Group(TastypieApikeys.Columns.UserID).OP("IN", PKArgExpr)), + )...) +} + +func insertAuthUserUserAuthUserGroups0(ctx context.Context, exec bob.Executor, authUserGroups1 []*AuthUserGroupSetter, authUser0 *AuthUser) (AuthUserGroupSlice, error) { + for i := range authUserGroups1 { + authUserGroups1[i].UserID = omit.From(authUser0.ID) + } + + ret, err := AuthUserGroups.Insert(bob.ToMods(authUserGroups1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthUserUserAuthUserGroups0: %w", err) + } + + return ret, nil +} + +func attachAuthUserUserAuthUserGroups0(ctx context.Context, exec bob.Executor, count int, authUserGroups1 AuthUserGroupSlice, authUser0 *AuthUser) (AuthUserGroupSlice, error) { + setter := &AuthUserGroupSetter{ + UserID: omit.From(authUser0.ID), + } + + err := authUserGroups1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserUserAuthUserGroups0: %w", err) + } + + return authUserGroups1, nil +} + +func (authUser0 *AuthUser) InsertUserAuthUserGroups(ctx context.Context, exec bob.Executor, related ...*AuthUserGroupSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + authUserGroups1, err := insertAuthUserUserAuthUserGroups0(ctx, exec, related, authUser0) + if err != nil { + return err + } + + authUser0.R.UserAuthUserGroups = append(authUser0.R.UserAuthUserGroups, authUserGroups1...) + + for _, rel := range authUserGroups1 { + rel.R.UserAuthUser = authUser0 + } + return nil +} + +func (authUser0 *AuthUser) AttachUserAuthUserGroups(ctx context.Context, exec bob.Executor, related ...*AuthUserGroup) error { + if len(related) == 0 { + return nil + } + + var err error + authUserGroups1 := AuthUserGroupSlice(related) + + _, err = attachAuthUserUserAuthUserGroups0(ctx, exec, len(related), authUserGroups1, authUser0) + if err != nil { + return err + } + + authUser0.R.UserAuthUserGroups = append(authUser0.R.UserAuthUserGroups, authUserGroups1...) + + for _, rel := range related { + rel.R.UserAuthUser = authUser0 + } + + return nil +} + +func insertAuthUserUserAuthUserUserPermissions0(ctx context.Context, exec bob.Executor, authUserUserPermissions1 []*AuthUserUserPermissionSetter, authUser0 *AuthUser) (AuthUserUserPermissionSlice, error) { + for i := range authUserUserPermissions1 { + authUserUserPermissions1[i].UserID = omit.From(authUser0.ID) + } + + ret, err := AuthUserUserPermissions.Insert(bob.ToMods(authUserUserPermissions1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthUserUserAuthUserUserPermissions0: %w", err) + } + + return ret, nil +} + +func attachAuthUserUserAuthUserUserPermissions0(ctx context.Context, exec bob.Executor, count int, authUserUserPermissions1 AuthUserUserPermissionSlice, authUser0 *AuthUser) (AuthUserUserPermissionSlice, error) { + setter := &AuthUserUserPermissionSetter{ + UserID: omit.From(authUser0.ID), + } + + err := authUserUserPermissions1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserUserAuthUserUserPermissions0: %w", err) + } + + return authUserUserPermissions1, nil +} + +func (authUser0 *AuthUser) InsertUserAuthUserUserPermissions(ctx context.Context, exec bob.Executor, related ...*AuthUserUserPermissionSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + authUserUserPermissions1, err := insertAuthUserUserAuthUserUserPermissions0(ctx, exec, related, authUser0) + if err != nil { + return err + } + + authUser0.R.UserAuthUserUserPermissions = append(authUser0.R.UserAuthUserUserPermissions, authUserUserPermissions1...) + + for _, rel := range authUserUserPermissions1 { + rel.R.UserAuthUser = authUser0 + } + return nil +} + +func (authUser0 *AuthUser) AttachUserAuthUserUserPermissions(ctx context.Context, exec bob.Executor, related ...*AuthUserUserPermission) error { + if len(related) == 0 { + return nil + } + + var err error + authUserUserPermissions1 := AuthUserUserPermissionSlice(related) + + _, err = attachAuthUserUserAuthUserUserPermissions0(ctx, exec, len(related), authUserUserPermissions1, authUser0) + if err != nil { + return err + } + + authUser0.R.UserAuthUserUserPermissions = append(authUser0.R.UserAuthUserUserPermissions, authUserUserPermissions1...) + + for _, rel := range related { + rel.R.UserAuthUser = authUser0 + } + + return nil +} + +func insertAuthUserUserDjangoAdminLogs0(ctx context.Context, exec bob.Executor, djangoAdminLogs1 []*DjangoAdminLogSetter, authUser0 *AuthUser) (DjangoAdminLogSlice, error) { + for i := range djangoAdminLogs1 { + djangoAdminLogs1[i].UserID = omit.From(authUser0.ID) + } + + ret, err := DjangoAdminLogs.Insert(bob.ToMods(djangoAdminLogs1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthUserUserDjangoAdminLogs0: %w", err) + } + + return ret, nil +} + +func attachAuthUserUserDjangoAdminLogs0(ctx context.Context, exec bob.Executor, count int, djangoAdminLogs1 DjangoAdminLogSlice, authUser0 *AuthUser) (DjangoAdminLogSlice, error) { + setter := &DjangoAdminLogSetter{ + UserID: omit.From(authUser0.ID), + } + + err := djangoAdminLogs1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserUserDjangoAdminLogs0: %w", err) + } + + return djangoAdminLogs1, nil +} + +func (authUser0 *AuthUser) InsertUserDjangoAdminLogs(ctx context.Context, exec bob.Executor, related ...*DjangoAdminLogSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + djangoAdminLogs1, err := insertAuthUserUserDjangoAdminLogs0(ctx, exec, related, authUser0) + if err != nil { + return err + } + + authUser0.R.UserDjangoAdminLogs = append(authUser0.R.UserDjangoAdminLogs, djangoAdminLogs1...) + + for _, rel := range djangoAdminLogs1 { + rel.R.UserAuthUser = authUser0 + } + return nil +} + +func (authUser0 *AuthUser) AttachUserDjangoAdminLogs(ctx context.Context, exec bob.Executor, related ...*DjangoAdminLog) error { + if len(related) == 0 { + return nil + } + + var err error + djangoAdminLogs1 := DjangoAdminLogSlice(related) + + _, err = attachAuthUserUserDjangoAdminLogs0(ctx, exec, len(related), djangoAdminLogs1, authUser0) + if err != nil { + return err + } + + authUser0.R.UserDjangoAdminLogs = append(authUser0.R.UserDjangoAdminLogs, djangoAdminLogs1...) + + for _, rel := range related { + rel.R.UserAuthUser = authUser0 + } + + return nil +} + +func insertAuthUserAdminIDLocationsEvents0(ctx context.Context, exec bob.Executor, locationsEvents1 []*LocationsEventSetter, authUser0 *AuthUser) (LocationsEventSlice, error) { + for i := range locationsEvents1 { + locationsEvents1[i].AdminIDID = omitnull.From(authUser0.ID) + } + + ret, err := LocationsEvents.Insert(bob.ToMods(locationsEvents1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthUserAdminIDLocationsEvents0: %w", err) + } + + return ret, nil +} + +func attachAuthUserAdminIDLocationsEvents0(ctx context.Context, exec bob.Executor, count int, locationsEvents1 LocationsEventSlice, authUser0 *AuthUser) (LocationsEventSlice, error) { + setter := &LocationsEventSetter{ + AdminIDID: omitnull.From(authUser0.ID), + } + + err := locationsEvents1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserAdminIDLocationsEvents0: %w", err) + } + + return locationsEvents1, nil +} + +func (authUser0 *AuthUser) InsertAdminIDLocationsEvents(ctx context.Context, exec bob.Executor, related ...*LocationsEventSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsEvents1, err := insertAuthUserAdminIDLocationsEvents0(ctx, exec, related, authUser0) + if err != nil { + return err + } + + authUser0.R.AdminIDLocationsEvents = append(authUser0.R.AdminIDLocationsEvents, locationsEvents1...) + + for _, rel := range locationsEvents1 { + rel.R.AdminIDAuthUser = authUser0 + } + return nil +} + +func (authUser0 *AuthUser) AttachAdminIDLocationsEvents(ctx context.Context, exec bob.Executor, related ...*LocationsEvent) error { + if len(related) == 0 { + return nil + } + + var err error + locationsEvents1 := LocationsEventSlice(related) + + _, err = attachAuthUserAdminIDLocationsEvents0(ctx, exec, len(related), locationsEvents1, authUser0) + if err != nil { + return err + } + + authUser0.R.AdminIDLocationsEvents = append(authUser0.R.AdminIDLocationsEvents, locationsEvents1...) + + for _, rel := range related { + rel.R.AdminIDAuthUser = authUser0 + } + + return nil +} + +func insertAuthUserUserTastypieApikey0(ctx context.Context, exec bob.Executor, tastypieApikey1 *TastypieApikeySetter, authUser0 *AuthUser) (*TastypieApikey, error) { + tastypieApikey1.UserID = omit.From(authUser0.ID) + + ret, err := TastypieApikeys.Insert(tastypieApikey1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthUserUserTastypieApikey0: %w", err) + } + + return ret, nil +} + +func attachAuthUserUserTastypieApikey0(ctx context.Context, exec bob.Executor, count int, tastypieApikey1 *TastypieApikey, authUser0 *AuthUser) (*TastypieApikey, error) { + setter := &TastypieApikeySetter{ + UserID: omit.From(authUser0.ID), + } + + err := tastypieApikey1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserUserTastypieApikey0: %w", err) + } + + return tastypieApikey1, nil +} + +func (authUser0 *AuthUser) InsertUserTastypieApikey(ctx context.Context, exec bob.Executor, related *TastypieApikeySetter) error { + var err error + + tastypieApikey1, err := insertAuthUserUserTastypieApikey0(ctx, exec, related, authUser0) + if err != nil { + return err + } + + authUser0.R.UserTastypieApikey = tastypieApikey1 + + tastypieApikey1.R.UserAuthUser = authUser0 + + return nil +} + +func (authUser0 *AuthUser) AttachUserTastypieApikey(ctx context.Context, exec bob.Executor, tastypieApikey1 *TastypieApikey) error { + var err error + + _, err = attachAuthUserUserTastypieApikey0(ctx, exec, 1, tastypieApikey1, authUser0) + if err != nil { + return err + } + + authUser0.R.UserTastypieApikey = tastypieApikey1 + + tastypieApikey1.R.UserAuthUser = authUser0 + + return nil +} + +type authUserWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Password mysql.WhereMod[Q, string] + LastLogin mysql.WhereNullMod[Q, time.Time] + IsSuperuser mysql.WhereMod[Q, bool] + Username mysql.WhereMod[Q, string] + FirstName mysql.WhereMod[Q, string] + LastName mysql.WhereMod[Q, string] + Email mysql.WhereMod[Q, string] + IsStaff mysql.WhereMod[Q, bool] + IsActive mysql.WhereMod[Q, bool] + DateJoined mysql.WhereMod[Q, time.Time] +} + +func (authUserWhere[Q]) AliasedAs(alias string) authUserWhere[Q] { + return buildAuthUserWhere[Q](buildAuthUserColumns(alias)) +} + +func buildAuthUserWhere[Q mysql.Filterable](cols authUserColumns) authUserWhere[Q] { + return authUserWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Password: mysql.Where[Q, string](cols.Password), + LastLogin: mysql.WhereNull[Q, time.Time](cols.LastLogin), + IsSuperuser: mysql.Where[Q, bool](cols.IsSuperuser), + Username: mysql.Where[Q, string](cols.Username), + FirstName: mysql.Where[Q, string](cols.FirstName), + LastName: mysql.Where[Q, string](cols.LastName), + Email: mysql.Where[Q, string](cols.Email), + IsStaff: mysql.Where[Q, bool](cols.IsStaff), + IsActive: mysql.Where[Q, bool](cols.IsActive), + DateJoined: mysql.Where[Q, time.Time](cols.DateJoined), + } +} + +func (o *AuthUser) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "UserAuthUserGroups": + rels, ok := retrieved.(AuthUserGroupSlice) + if !ok { + return fmt.Errorf("authUser cannot load %T as %q", retrieved, name) + } + + o.R.UserAuthUserGroups = rels + + for _, rel := range rels { + if rel != nil { + rel.R.UserAuthUser = o + } + } + return nil + case "UserAuthUserUserPermissions": + rels, ok := retrieved.(AuthUserUserPermissionSlice) + if !ok { + return fmt.Errorf("authUser cannot load %T as %q", retrieved, name) + } + + o.R.UserAuthUserUserPermissions = rels + + for _, rel := range rels { + if rel != nil { + rel.R.UserAuthUser = o + } + } + return nil + case "UserDjangoAdminLogs": + rels, ok := retrieved.(DjangoAdminLogSlice) + if !ok { + return fmt.Errorf("authUser cannot load %T as %q", retrieved, name) + } + + o.R.UserDjangoAdminLogs = rels + + for _, rel := range rels { + if rel != nil { + rel.R.UserAuthUser = o + } + } + return nil + case "AdminIDLocationsEvents": + rels, ok := retrieved.(LocationsEventSlice) + if !ok { + return fmt.Errorf("authUser cannot load %T as %q", retrieved, name) + } + + o.R.AdminIDLocationsEvents = rels + + for _, rel := range rels { + if rel != nil { + rel.R.AdminIDAuthUser = o + } + } + return nil + case "UserTastypieApikey": + rel, ok := retrieved.(*TastypieApikey) + if !ok { + return fmt.Errorf("authUser cannot load %T as %q", retrieved, name) + } + + o.R.UserTastypieApikey = rel + + if rel != nil { + rel.R.UserAuthUser = o + } + return nil + default: + return fmt.Errorf("authUser has no relationship %q", name) + } +} + +type authUserPreloader struct { + UserTastypieApikey func(...mysql.PreloadOption) mysql.Preloader +} + +func buildAuthUserPreloader() authUserPreloader { + return authUserPreloader{ + UserTastypieApikey: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*TastypieApikey, TastypieApikeySlice](mysql.PreloadRel{ + Name: "UserTastypieApikey", + Sides: []mysql.PreloadSide{ + { + From: AuthUsers, + To: TastypieApikeys, + FromColumns: []string{"id"}, + ToColumns: []string{"user_id"}, + }, + }, + }, TastypieApikeys.Columns.Names(), opts...) + }, + } +} + +type authUserThenLoader[Q orm.Loadable] struct { + UserAuthUserGroups func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + UserAuthUserUserPermissions func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + UserDjangoAdminLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + AdminIDLocationsEvents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + UserTastypieApikey func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildAuthUserThenLoader[Q orm.Loadable]() authUserThenLoader[Q] { + type UserAuthUserGroupsLoadInterface interface { + LoadUserAuthUserGroups(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type UserAuthUserUserPermissionsLoadInterface interface { + LoadUserAuthUserUserPermissions(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type UserDjangoAdminLogsLoadInterface interface { + LoadUserDjangoAdminLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type AdminIDLocationsEventsLoadInterface interface { + LoadAdminIDLocationsEvents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type UserTastypieApikeyLoadInterface interface { + LoadUserTastypieApikey(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return authUserThenLoader[Q]{ + UserAuthUserGroups: thenLoadBuilder[Q]( + "UserAuthUserGroups", + func(ctx context.Context, exec bob.Executor, retrieved UserAuthUserGroupsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUserAuthUserGroups(ctx, exec, mods...) + }, + ), + UserAuthUserUserPermissions: thenLoadBuilder[Q]( + "UserAuthUserUserPermissions", + func(ctx context.Context, exec bob.Executor, retrieved UserAuthUserUserPermissionsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUserAuthUserUserPermissions(ctx, exec, mods...) + }, + ), + UserDjangoAdminLogs: thenLoadBuilder[Q]( + "UserDjangoAdminLogs", + func(ctx context.Context, exec bob.Executor, retrieved UserDjangoAdminLogsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUserDjangoAdminLogs(ctx, exec, mods...) + }, + ), + AdminIDLocationsEvents: thenLoadBuilder[Q]( + "AdminIDLocationsEvents", + func(ctx context.Context, exec bob.Executor, retrieved AdminIDLocationsEventsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadAdminIDLocationsEvents(ctx, exec, mods...) + }, + ), + UserTastypieApikey: thenLoadBuilder[Q]( + "UserTastypieApikey", + func(ctx context.Context, exec bob.Executor, retrieved UserTastypieApikeyLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUserTastypieApikey(ctx, exec, mods...) + }, + ), + } +} + +// LoadUserAuthUserGroups loads the authUser's UserAuthUserGroups into the .R struct +func (o *AuthUser) LoadUserAuthUserGroups(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UserAuthUserGroups = nil + + related, err := o.UserAuthUserGroups(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.UserAuthUser = o + } + + o.R.UserAuthUserGroups = related + return nil +} + +// LoadUserAuthUserGroups loads the authUser's UserAuthUserGroups into the .R struct +func (os AuthUserSlice) LoadUserAuthUserGroups(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUserGroups, err := os.UserAuthUserGroups(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.UserAuthUserGroups = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUserGroups { + + if !(o.ID == rel.UserID) { + continue + } + + rel.R.UserAuthUser = o + + o.R.UserAuthUserGroups = append(o.R.UserAuthUserGroups, rel) + } + } + + return nil +} + +// LoadUserAuthUserUserPermissions loads the authUser's UserAuthUserUserPermissions into the .R struct +func (o *AuthUser) LoadUserAuthUserUserPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UserAuthUserUserPermissions = nil + + related, err := o.UserAuthUserUserPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.UserAuthUser = o + } + + o.R.UserAuthUserUserPermissions = related + return nil +} + +// LoadUserAuthUserUserPermissions loads the authUser's UserAuthUserUserPermissions into the .R struct +func (os AuthUserSlice) LoadUserAuthUserUserPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUserUserPermissions, err := os.UserAuthUserUserPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.UserAuthUserUserPermissions = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUserUserPermissions { + + if !(o.ID == rel.UserID) { + continue + } + + rel.R.UserAuthUser = o + + o.R.UserAuthUserUserPermissions = append(o.R.UserAuthUserUserPermissions, rel) + } + } + + return nil +} + +// LoadUserDjangoAdminLogs loads the authUser's UserDjangoAdminLogs into the .R struct +func (o *AuthUser) LoadUserDjangoAdminLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UserDjangoAdminLogs = nil + + related, err := o.UserDjangoAdminLogs(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.UserAuthUser = o + } + + o.R.UserDjangoAdminLogs = related + return nil +} + +// LoadUserDjangoAdminLogs loads the authUser's UserDjangoAdminLogs into the .R struct +func (os AuthUserSlice) LoadUserDjangoAdminLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + djangoAdminLogs, err := os.UserDjangoAdminLogs(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.UserDjangoAdminLogs = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range djangoAdminLogs { + + if !(o.ID == rel.UserID) { + continue + } + + rel.R.UserAuthUser = o + + o.R.UserDjangoAdminLogs = append(o.R.UserDjangoAdminLogs, rel) + } + } + + return nil +} + +// LoadAdminIDLocationsEvents loads the authUser's AdminIDLocationsEvents into the .R struct +func (o *AuthUser) LoadAdminIDLocationsEvents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.AdminIDLocationsEvents = nil + + related, err := o.AdminIDLocationsEvents(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.AdminIDAuthUser = o + } + + o.R.AdminIDLocationsEvents = related + return nil +} + +// LoadAdminIDLocationsEvents loads the authUser's AdminIDLocationsEvents into the .R struct +func (os AuthUserSlice) LoadAdminIDLocationsEvents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsEvents, err := os.AdminIDLocationsEvents(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.AdminIDLocationsEvents = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsEvents { + + if !rel.AdminIDID.IsValue() { + continue + } + if !(rel.AdminIDID.IsValue() && o.ID == rel.AdminIDID.MustGet()) { + continue + } + + rel.R.AdminIDAuthUser = o + + o.R.AdminIDLocationsEvents = append(o.R.AdminIDLocationsEvents, rel) + } + } + + return nil +} + +// LoadUserTastypieApikey loads the authUser's UserTastypieApikey into the .R struct +func (o *AuthUser) LoadUserTastypieApikey(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UserTastypieApikey = nil + + related, err := o.UserTastypieApikey(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.UserAuthUser = o + + o.R.UserTastypieApikey = related + return nil +} + +// LoadUserTastypieApikey loads the authUser's UserTastypieApikey into the .R struct +func (os AuthUserSlice) LoadUserTastypieApikey(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + tastypieApikeys, err := os.UserTastypieApikey(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range tastypieApikeys { + + if !(o.ID == rel.UserID) { + continue + } + + rel.R.UserAuthUser = o + + o.R.UserTastypieApikey = rel + break + } + } + + return nil +} + +type authUserJoins[Q dialect.Joinable] struct { + typ string + UserAuthUserGroups modAs[Q, authUserGroupColumns] + UserAuthUserUserPermissions modAs[Q, authUserUserPermissionColumns] + UserDjangoAdminLogs modAs[Q, djangoAdminLogColumns] + AdminIDLocationsEvents modAs[Q, locationsEventColumns] + UserTastypieApikey modAs[Q, tastypieApikeyColumns] +} + +func (j authUserJoins[Q]) aliasedAs(alias string) authUserJoins[Q] { + return buildAuthUserJoins[Q](buildAuthUserColumns(alias), j.typ) +} + +func buildAuthUserJoins[Q dialect.Joinable](cols authUserColumns, typ string) authUserJoins[Q] { + return authUserJoins[Q]{ + typ: typ, + UserAuthUserGroups: modAs[Q, authUserGroupColumns]{ + c: AuthUserGroups.Columns, + f: func(to authUserGroupColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUserGroups.Name().As(to.Alias())).On( + to.UserID.EQ(cols.ID), + )) + } + + return mods + }, + }, + UserAuthUserUserPermissions: modAs[Q, authUserUserPermissionColumns]{ + c: AuthUserUserPermissions.Columns, + f: func(to authUserUserPermissionColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUserUserPermissions.Name().As(to.Alias())).On( + to.UserID.EQ(cols.ID), + )) + } + + return mods + }, + }, + UserDjangoAdminLogs: modAs[Q, djangoAdminLogColumns]{ + c: DjangoAdminLogs.Columns, + f: func(to djangoAdminLogColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, DjangoAdminLogs.Name().As(to.Alias())).On( + to.UserID.EQ(cols.ID), + )) + } + + return mods + }, + }, + AdminIDLocationsEvents: modAs[Q, locationsEventColumns]{ + c: LocationsEvents.Columns, + f: func(to locationsEventColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsEvents.Name().As(to.Alias())).On( + to.AdminIDID.EQ(cols.ID), + )) + } + + return mods + }, + }, + UserTastypieApikey: modAs[Q, tastypieApikeyColumns]{ + c: TastypieApikeys.Columns, + f: func(to tastypieApikeyColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, TastypieApikeys.Name().As(to.Alias())).On( + to.UserID.EQ(cols.ID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/auth_user_groups.bob.go b/database/mcp/models/auth_user_groups.bob.go new file mode 100644 index 0000000..d76ee3c --- /dev/null +++ b/database/mcp/models/auth_user_groups.bob.go @@ -0,0 +1,787 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// AuthUserGroup is an object representing the database table. +type AuthUserGroup struct { + ID int32 `db:"id,pk,autoincr" ` + UserID int32 `db:"user_id" ` + GroupID int32 `db:"group_id" ` + + R authUserGroupR `db:"-" ` +} + +// AuthUserGroupSlice is an alias for a slice of pointers to AuthUserGroup. +// This should almost always be used instead of []*AuthUserGroup. +type AuthUserGroupSlice []*AuthUserGroup + +// AuthUserGroups contains methods to work with the auth_user_groups table +var AuthUserGroups = mysql.NewTablex[*AuthUserGroup, AuthUserGroupSlice, *AuthUserGroupSetter]("auth_user_groups", buildAuthUserGroupColumns("auth_user_groups"), []string{"id"}, []string{"user_id", "group_id"}) + +// AuthUserGroupsQuery is a query on the auth_user_groups table +type AuthUserGroupsQuery = *mysql.ViewQuery[*AuthUserGroup, AuthUserGroupSlice] + +// authUserGroupR is where relationships are stored. +type authUserGroupR struct { + GroupAuthGroup *AuthGroup // auth_user_groups_group_id_97559544_fk_auth_group_id + UserAuthUser *AuthUser // auth_user_groups_user_id_6a12ed8b_fk_auth_user_id +} + +func buildAuthUserGroupColumns(alias string) authUserGroupColumns { + return authUserGroupColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "user_id", "group_id", + ).WithParent("auth_user_groups"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UserID: mysql.Quote(alias, "user_id"), + GroupID: mysql.Quote(alias, "group_id"), + } +} + +type authUserGroupColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UserID mysql.Expression + GroupID mysql.Expression +} + +func (c authUserGroupColumns) Alias() string { + return c.tableAlias +} + +func (authUserGroupColumns) AliasedAs(alias string) authUserGroupColumns { + return buildAuthUserGroupColumns(alias) +} + +// AuthUserGroupSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type AuthUserGroupSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UserID omit.Val[int32] `db:"user_id" ` + GroupID omit.Val[int32] `db:"group_id" ` +} + +func (s AuthUserGroupSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UserID.IsValue() { + vals = append(vals, "user_id") + } + if s.GroupID.IsValue() { + vals = append(vals, "group_id") + } + return vals +} + +func (s AuthUserGroupSetter) Overwrite(t *AuthUserGroup) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UserID.IsValue() { + t.UserID = s.UserID.MustGet() + } + if s.GroupID.IsValue() { + t.GroupID = s.GroupID.MustGet() + } +} + +func (s *AuthUserGroupSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUserGroups.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UserID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UserID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.GroupID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.GroupID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s AuthUserGroupSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("auth_user_groups")...) +} + +func (s AuthUserGroupSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UserID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "user_id")...), + mysql.Arg(s.UserID), + }}) + } + + if s.GroupID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "group_id")...), + mysql.Arg(s.GroupID), + }}) + } + + return exprs +} + +// FindAuthUserGroup retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindAuthUserGroup(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*AuthUserGroup, error) { + if len(cols) == 0 { + return AuthUserGroups.Query( + sm.Where(AuthUserGroups.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return AuthUserGroups.Query( + sm.Where(AuthUserGroups.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(AuthUserGroups.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// AuthUserGroupExists checks the presence of a single record by primary key +func AuthUserGroupExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return AuthUserGroups.Query( + sm.Where(AuthUserGroups.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after AuthUserGroup is retrieved from the database +func (o *AuthUserGroup) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthUserGroups.AfterSelectHooks.RunHooks(ctx, exec, AuthUserGroupSlice{o}) + case bob.QueryTypeInsert: + ctx, err = AuthUserGroups.AfterInsertHooks.RunHooks(ctx, exec, AuthUserGroupSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = AuthUserGroups.AfterUpdateHooks.RunHooks(ctx, exec, AuthUserGroupSlice{o}) + case bob.QueryTypeDelete: + ctx, err = AuthUserGroups.AfterDeleteHooks.RunHooks(ctx, exec, AuthUserGroupSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the AuthUserGroup +func (o *AuthUserGroup) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *AuthUserGroup) pkEQ() dialect.Expression { + return mysql.Quote("auth_user_groups", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the AuthUserGroup +func (o *AuthUserGroup) Update(ctx context.Context, exec bob.Executor, s *AuthUserGroupSetter) error { + _, err := AuthUserGroups.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single AuthUserGroup record with an executor +func (o *AuthUserGroup) Delete(ctx context.Context, exec bob.Executor) error { + _, err := AuthUserGroups.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the AuthUserGroup using the executor +func (o *AuthUserGroup) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := AuthUserGroups.Query( + sm.Where(AuthUserGroups.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after AuthUserGroupSlice is retrieved from the database +func (o AuthUserGroupSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthUserGroups.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = AuthUserGroups.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = AuthUserGroups.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = AuthUserGroups.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o AuthUserGroupSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("auth_user_groups", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o AuthUserGroupSlice) copyMatchingRows(from ...*AuthUserGroup) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o AuthUserGroupSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUserGroups.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthUserGroup: + o.copyMatchingRows(retrieved) + case []*AuthUserGroup: + o.copyMatchingRows(retrieved...) + case AuthUserGroupSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthUserGroup or a slice of AuthUserGroup + // then run the AfterUpdateHooks on the slice + _, err = AuthUserGroups.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o AuthUserGroupSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUserGroups.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthUserGroup: + o.copyMatchingRows(retrieved) + case []*AuthUserGroup: + o.copyMatchingRows(retrieved...) + case AuthUserGroupSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthUserGroup or a slice of AuthUserGroup + // then run the AfterDeleteHooks on the slice + _, err = AuthUserGroups.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o AuthUserGroupSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals AuthUserGroupSetter) error { + _, err := AuthUserGroups.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o AuthUserGroupSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := AuthUserGroups.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o AuthUserGroupSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := AuthUserGroups.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// GroupAuthGroup starts a query for related objects on auth_group +func (o *AuthUserGroup) GroupAuthGroup(mods ...bob.Mod[*dialect.SelectQuery]) AuthGroupsQuery { + return AuthGroups.Query(append(mods, + sm.Where(AuthGroups.Columns.ID.EQ(mysql.Arg(o.GroupID))), + )...) +} + +func (os AuthUserGroupSlice) GroupAuthGroup(mods ...bob.Mod[*dialect.SelectQuery]) AuthGroupsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.GroupID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthGroups.Query(append(mods, + sm.Where(mysql.Group(AuthGroups.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// UserAuthUser starts a query for related objects on auth_user +func (o *AuthUserGroup) UserAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + return AuthUsers.Query(append(mods, + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(o.UserID))), + )...) +} + +func (os AuthUserGroupSlice) UserAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UserID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUsers.Query(append(mods, + sm.Where(mysql.Group(AuthUsers.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func attachAuthUserGroupGroupAuthGroup0(ctx context.Context, exec bob.Executor, count int, authUserGroup0 *AuthUserGroup, authGroup1 *AuthGroup) (*AuthUserGroup, error) { + setter := &AuthUserGroupSetter{ + GroupID: omit.From(authGroup1.ID), + } + + err := authUserGroup0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserGroupGroupAuthGroup0: %w", err) + } + + return authUserGroup0, nil +} + +func (authUserGroup0 *AuthUserGroup) InsertGroupAuthGroup(ctx context.Context, exec bob.Executor, related *AuthGroupSetter) error { + var err error + + authGroup1, err := AuthGroups.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachAuthUserGroupGroupAuthGroup0(ctx, exec, 1, authUserGroup0, authGroup1) + if err != nil { + return err + } + + authUserGroup0.R.GroupAuthGroup = authGroup1 + + authGroup1.R.GroupAuthUserGroups = append(authGroup1.R.GroupAuthUserGroups, authUserGroup0) + + return nil +} + +func (authUserGroup0 *AuthUserGroup) AttachGroupAuthGroup(ctx context.Context, exec bob.Executor, authGroup1 *AuthGroup) error { + var err error + + _, err = attachAuthUserGroupGroupAuthGroup0(ctx, exec, 1, authUserGroup0, authGroup1) + if err != nil { + return err + } + + authUserGroup0.R.GroupAuthGroup = authGroup1 + + authGroup1.R.GroupAuthUserGroups = append(authGroup1.R.GroupAuthUserGroups, authUserGroup0) + + return nil +} + +func attachAuthUserGroupUserAuthUser0(ctx context.Context, exec bob.Executor, count int, authUserGroup0 *AuthUserGroup, authUser1 *AuthUser) (*AuthUserGroup, error) { + setter := &AuthUserGroupSetter{ + UserID: omit.From(authUser1.ID), + } + + err := authUserGroup0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserGroupUserAuthUser0: %w", err) + } + + return authUserGroup0, nil +} + +func (authUserGroup0 *AuthUserGroup) InsertUserAuthUser(ctx context.Context, exec bob.Executor, related *AuthUserSetter) error { + var err error + + authUser1, err := AuthUsers.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachAuthUserGroupUserAuthUser0(ctx, exec, 1, authUserGroup0, authUser1) + if err != nil { + return err + } + + authUserGroup0.R.UserAuthUser = authUser1 + + authUser1.R.UserAuthUserGroups = append(authUser1.R.UserAuthUserGroups, authUserGroup0) + + return nil +} + +func (authUserGroup0 *AuthUserGroup) AttachUserAuthUser(ctx context.Context, exec bob.Executor, authUser1 *AuthUser) error { + var err error + + _, err = attachAuthUserGroupUserAuthUser0(ctx, exec, 1, authUserGroup0, authUser1) + if err != nil { + return err + } + + authUserGroup0.R.UserAuthUser = authUser1 + + authUser1.R.UserAuthUserGroups = append(authUser1.R.UserAuthUserGroups, authUserGroup0) + + return nil +} + +type authUserGroupWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UserID mysql.WhereMod[Q, int32] + GroupID mysql.WhereMod[Q, int32] +} + +func (authUserGroupWhere[Q]) AliasedAs(alias string) authUserGroupWhere[Q] { + return buildAuthUserGroupWhere[Q](buildAuthUserGroupColumns(alias)) +} + +func buildAuthUserGroupWhere[Q mysql.Filterable](cols authUserGroupColumns) authUserGroupWhere[Q] { + return authUserGroupWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UserID: mysql.Where[Q, int32](cols.UserID), + GroupID: mysql.Where[Q, int32](cols.GroupID), + } +} + +func (o *AuthUserGroup) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "GroupAuthGroup": + rel, ok := retrieved.(*AuthGroup) + if !ok { + return fmt.Errorf("authUserGroup cannot load %T as %q", retrieved, name) + } + + o.R.GroupAuthGroup = rel + + if rel != nil { + rel.R.GroupAuthUserGroups = AuthUserGroupSlice{o} + } + return nil + case "UserAuthUser": + rel, ok := retrieved.(*AuthUser) + if !ok { + return fmt.Errorf("authUserGroup cannot load %T as %q", retrieved, name) + } + + o.R.UserAuthUser = rel + + if rel != nil { + rel.R.UserAuthUserGroups = AuthUserGroupSlice{o} + } + return nil + default: + return fmt.Errorf("authUserGroup has no relationship %q", name) + } +} + +type authUserGroupPreloader struct { + GroupAuthGroup func(...mysql.PreloadOption) mysql.Preloader + UserAuthUser func(...mysql.PreloadOption) mysql.Preloader +} + +func buildAuthUserGroupPreloader() authUserGroupPreloader { + return authUserGroupPreloader{ + GroupAuthGroup: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthGroup, AuthGroupSlice](mysql.PreloadRel{ + Name: "GroupAuthGroup", + Sides: []mysql.PreloadSide{ + { + From: AuthUserGroups, + To: AuthGroups, + FromColumns: []string{"group_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthGroups.Columns.Names(), opts...) + }, + UserAuthUser: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthUser, AuthUserSlice](mysql.PreloadRel{ + Name: "UserAuthUser", + Sides: []mysql.PreloadSide{ + { + From: AuthUserGroups, + To: AuthUsers, + FromColumns: []string{"user_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthUsers.Columns.Names(), opts...) + }, + } +} + +type authUserGroupThenLoader[Q orm.Loadable] struct { + GroupAuthGroup func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + UserAuthUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildAuthUserGroupThenLoader[Q orm.Loadable]() authUserGroupThenLoader[Q] { + type GroupAuthGroupLoadInterface interface { + LoadGroupAuthGroup(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type UserAuthUserLoadInterface interface { + LoadUserAuthUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return authUserGroupThenLoader[Q]{ + GroupAuthGroup: thenLoadBuilder[Q]( + "GroupAuthGroup", + func(ctx context.Context, exec bob.Executor, retrieved GroupAuthGroupLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadGroupAuthGroup(ctx, exec, mods...) + }, + ), + UserAuthUser: thenLoadBuilder[Q]( + "UserAuthUser", + func(ctx context.Context, exec bob.Executor, retrieved UserAuthUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUserAuthUser(ctx, exec, mods...) + }, + ), + } +} + +// LoadGroupAuthGroup loads the authUserGroup's GroupAuthGroup into the .R struct +func (o *AuthUserGroup) LoadGroupAuthGroup(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.GroupAuthGroup = nil + + related, err := o.GroupAuthGroup(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.GroupAuthUserGroups = AuthUserGroupSlice{o} + + o.R.GroupAuthGroup = related + return nil +} + +// LoadGroupAuthGroup loads the authUserGroup's GroupAuthGroup into the .R struct +func (os AuthUserGroupSlice) LoadGroupAuthGroup(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authGroups, err := os.GroupAuthGroup(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authGroups { + + if !(o.GroupID == rel.ID) { + continue + } + + rel.R.GroupAuthUserGroups = append(rel.R.GroupAuthUserGroups, o) + + o.R.GroupAuthGroup = rel + break + } + } + + return nil +} + +// LoadUserAuthUser loads the authUserGroup's UserAuthUser into the .R struct +func (o *AuthUserGroup) LoadUserAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UserAuthUser = nil + + related, err := o.UserAuthUser(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.UserAuthUserGroups = AuthUserGroupSlice{o} + + o.R.UserAuthUser = related + return nil +} + +// LoadUserAuthUser loads the authUserGroup's UserAuthUser into the .R struct +func (os AuthUserGroupSlice) LoadUserAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUsers, err := os.UserAuthUser(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUsers { + + if !(o.UserID == rel.ID) { + continue + } + + rel.R.UserAuthUserGroups = append(rel.R.UserAuthUserGroups, o) + + o.R.UserAuthUser = rel + break + } + } + + return nil +} + +type authUserGroupJoins[Q dialect.Joinable] struct { + typ string + GroupAuthGroup modAs[Q, authGroupColumns] + UserAuthUser modAs[Q, authUserColumns] +} + +func (j authUserGroupJoins[Q]) aliasedAs(alias string) authUserGroupJoins[Q] { + return buildAuthUserGroupJoins[Q](buildAuthUserGroupColumns(alias), j.typ) +} + +func buildAuthUserGroupJoins[Q dialect.Joinable](cols authUserGroupColumns, typ string) authUserGroupJoins[Q] { + return authUserGroupJoins[Q]{ + typ: typ, + GroupAuthGroup: modAs[Q, authGroupColumns]{ + c: AuthGroups.Columns, + f: func(to authGroupColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthGroups.Name().As(to.Alias())).On( + to.ID.EQ(cols.GroupID), + )) + } + + return mods + }, + }, + UserAuthUser: modAs[Q, authUserColumns]{ + c: AuthUsers.Columns, + f: func(to authUserColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUsers.Name().As(to.Alias())).On( + to.ID.EQ(cols.UserID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/auth_user_user_permissions.bob.go b/database/mcp/models/auth_user_user_permissions.bob.go new file mode 100644 index 0000000..8bb7633 --- /dev/null +++ b/database/mcp/models/auth_user_user_permissions.bob.go @@ -0,0 +1,787 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// AuthUserUserPermission is an object representing the database table. +type AuthUserUserPermission struct { + ID int32 `db:"id,pk,autoincr" ` + UserID int32 `db:"user_id" ` + PermissionID int32 `db:"permission_id" ` + + R authUserUserPermissionR `db:"-" ` +} + +// AuthUserUserPermissionSlice is an alias for a slice of pointers to AuthUserUserPermission. +// This should almost always be used instead of []*AuthUserUserPermission. +type AuthUserUserPermissionSlice []*AuthUserUserPermission + +// AuthUserUserPermissions contains methods to work with the auth_user_user_permissions table +var AuthUserUserPermissions = mysql.NewTablex[*AuthUserUserPermission, AuthUserUserPermissionSlice, *AuthUserUserPermissionSetter]("auth_user_user_permissions", buildAuthUserUserPermissionColumns("auth_user_user_permissions"), []string{"id"}, []string{"user_id", "permission_id"}) + +// AuthUserUserPermissionsQuery is a query on the auth_user_user_permissions table +type AuthUserUserPermissionsQuery = *mysql.ViewQuery[*AuthUserUserPermission, AuthUserUserPermissionSlice] + +// authUserUserPermissionR is where relationships are stored. +type authUserUserPermissionR struct { + PermissionAuthPermission *AuthPermission // auth_user_user_permi_permission_id_1fbb5f2c_fk_auth_perm + UserAuthUser *AuthUser // auth_user_user_permissions_user_id_a95ead1b_fk_auth_user_id +} + +func buildAuthUserUserPermissionColumns(alias string) authUserUserPermissionColumns { + return authUserUserPermissionColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "user_id", "permission_id", + ).WithParent("auth_user_user_permissions"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UserID: mysql.Quote(alias, "user_id"), + PermissionID: mysql.Quote(alias, "permission_id"), + } +} + +type authUserUserPermissionColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UserID mysql.Expression + PermissionID mysql.Expression +} + +func (c authUserUserPermissionColumns) Alias() string { + return c.tableAlias +} + +func (authUserUserPermissionColumns) AliasedAs(alias string) authUserUserPermissionColumns { + return buildAuthUserUserPermissionColumns(alias) +} + +// AuthUserUserPermissionSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type AuthUserUserPermissionSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UserID omit.Val[int32] `db:"user_id" ` + PermissionID omit.Val[int32] `db:"permission_id" ` +} + +func (s AuthUserUserPermissionSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UserID.IsValue() { + vals = append(vals, "user_id") + } + if s.PermissionID.IsValue() { + vals = append(vals, "permission_id") + } + return vals +} + +func (s AuthUserUserPermissionSetter) Overwrite(t *AuthUserUserPermission) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UserID.IsValue() { + t.UserID = s.UserID.MustGet() + } + if s.PermissionID.IsValue() { + t.PermissionID = s.PermissionID.MustGet() + } +} + +func (s *AuthUserUserPermissionSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUserUserPermissions.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UserID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UserID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.PermissionID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PermissionID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s AuthUserUserPermissionSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("auth_user_user_permissions")...) +} + +func (s AuthUserUserPermissionSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UserID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "user_id")...), + mysql.Arg(s.UserID), + }}) + } + + if s.PermissionID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "permission_id")...), + mysql.Arg(s.PermissionID), + }}) + } + + return exprs +} + +// FindAuthUserUserPermission retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindAuthUserUserPermission(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*AuthUserUserPermission, error) { + if len(cols) == 0 { + return AuthUserUserPermissions.Query( + sm.Where(AuthUserUserPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return AuthUserUserPermissions.Query( + sm.Where(AuthUserUserPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(AuthUserUserPermissions.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// AuthUserUserPermissionExists checks the presence of a single record by primary key +func AuthUserUserPermissionExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return AuthUserUserPermissions.Query( + sm.Where(AuthUserUserPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after AuthUserUserPermission is retrieved from the database +func (o *AuthUserUserPermission) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthUserUserPermissions.AfterSelectHooks.RunHooks(ctx, exec, AuthUserUserPermissionSlice{o}) + case bob.QueryTypeInsert: + ctx, err = AuthUserUserPermissions.AfterInsertHooks.RunHooks(ctx, exec, AuthUserUserPermissionSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = AuthUserUserPermissions.AfterUpdateHooks.RunHooks(ctx, exec, AuthUserUserPermissionSlice{o}) + case bob.QueryTypeDelete: + ctx, err = AuthUserUserPermissions.AfterDeleteHooks.RunHooks(ctx, exec, AuthUserUserPermissionSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the AuthUserUserPermission +func (o *AuthUserUserPermission) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *AuthUserUserPermission) pkEQ() dialect.Expression { + return mysql.Quote("auth_user_user_permissions", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the AuthUserUserPermission +func (o *AuthUserUserPermission) Update(ctx context.Context, exec bob.Executor, s *AuthUserUserPermissionSetter) error { + _, err := AuthUserUserPermissions.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single AuthUserUserPermission record with an executor +func (o *AuthUserUserPermission) Delete(ctx context.Context, exec bob.Executor) error { + _, err := AuthUserUserPermissions.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the AuthUserUserPermission using the executor +func (o *AuthUserUserPermission) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := AuthUserUserPermissions.Query( + sm.Where(AuthUserUserPermissions.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after AuthUserUserPermissionSlice is retrieved from the database +func (o AuthUserUserPermissionSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthUserUserPermissions.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = AuthUserUserPermissions.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = AuthUserUserPermissions.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = AuthUserUserPermissions.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o AuthUserUserPermissionSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("auth_user_user_permissions", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o AuthUserUserPermissionSlice) copyMatchingRows(from ...*AuthUserUserPermission) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o AuthUserUserPermissionSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUserUserPermissions.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthUserUserPermission: + o.copyMatchingRows(retrieved) + case []*AuthUserUserPermission: + o.copyMatchingRows(retrieved...) + case AuthUserUserPermissionSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthUserUserPermission or a slice of AuthUserUserPermission + // then run the AfterUpdateHooks on the slice + _, err = AuthUserUserPermissions.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o AuthUserUserPermissionSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUserUserPermissions.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthUserUserPermission: + o.copyMatchingRows(retrieved) + case []*AuthUserUserPermission: + o.copyMatchingRows(retrieved...) + case AuthUserUserPermissionSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthUserUserPermission or a slice of AuthUserUserPermission + // then run the AfterDeleteHooks on the slice + _, err = AuthUserUserPermissions.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o AuthUserUserPermissionSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals AuthUserUserPermissionSetter) error { + _, err := AuthUserUserPermissions.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o AuthUserUserPermissionSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := AuthUserUserPermissions.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o AuthUserUserPermissionSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := AuthUserUserPermissions.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// PermissionAuthPermission starts a query for related objects on auth_permission +func (o *AuthUserUserPermission) PermissionAuthPermission(mods ...bob.Mod[*dialect.SelectQuery]) AuthPermissionsQuery { + return AuthPermissions.Query(append(mods, + sm.Where(AuthPermissions.Columns.ID.EQ(mysql.Arg(o.PermissionID))), + )...) +} + +func (os AuthUserUserPermissionSlice) PermissionAuthPermission(mods ...bob.Mod[*dialect.SelectQuery]) AuthPermissionsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PermissionID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthPermissions.Query(append(mods, + sm.Where(mysql.Group(AuthPermissions.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// UserAuthUser starts a query for related objects on auth_user +func (o *AuthUserUserPermission) UserAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + return AuthUsers.Query(append(mods, + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(o.UserID))), + )...) +} + +func (os AuthUserUserPermissionSlice) UserAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UserID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUsers.Query(append(mods, + sm.Where(mysql.Group(AuthUsers.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func attachAuthUserUserPermissionPermissionAuthPermission0(ctx context.Context, exec bob.Executor, count int, authUserUserPermission0 *AuthUserUserPermission, authPermission1 *AuthPermission) (*AuthUserUserPermission, error) { + setter := &AuthUserUserPermissionSetter{ + PermissionID: omit.From(authPermission1.ID), + } + + err := authUserUserPermission0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserUserPermissionPermissionAuthPermission0: %w", err) + } + + return authUserUserPermission0, nil +} + +func (authUserUserPermission0 *AuthUserUserPermission) InsertPermissionAuthPermission(ctx context.Context, exec bob.Executor, related *AuthPermissionSetter) error { + var err error + + authPermission1, err := AuthPermissions.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachAuthUserUserPermissionPermissionAuthPermission0(ctx, exec, 1, authUserUserPermission0, authPermission1) + if err != nil { + return err + } + + authUserUserPermission0.R.PermissionAuthPermission = authPermission1 + + authPermission1.R.PermissionAuthUserUserPermissions = append(authPermission1.R.PermissionAuthUserUserPermissions, authUserUserPermission0) + + return nil +} + +func (authUserUserPermission0 *AuthUserUserPermission) AttachPermissionAuthPermission(ctx context.Context, exec bob.Executor, authPermission1 *AuthPermission) error { + var err error + + _, err = attachAuthUserUserPermissionPermissionAuthPermission0(ctx, exec, 1, authUserUserPermission0, authPermission1) + if err != nil { + return err + } + + authUserUserPermission0.R.PermissionAuthPermission = authPermission1 + + authPermission1.R.PermissionAuthUserUserPermissions = append(authPermission1.R.PermissionAuthUserUserPermissions, authUserUserPermission0) + + return nil +} + +func attachAuthUserUserPermissionUserAuthUser0(ctx context.Context, exec bob.Executor, count int, authUserUserPermission0 *AuthUserUserPermission, authUser1 *AuthUser) (*AuthUserUserPermission, error) { + setter := &AuthUserUserPermissionSetter{ + UserID: omit.From(authUser1.ID), + } + + err := authUserUserPermission0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserUserPermissionUserAuthUser0: %w", err) + } + + return authUserUserPermission0, nil +} + +func (authUserUserPermission0 *AuthUserUserPermission) InsertUserAuthUser(ctx context.Context, exec bob.Executor, related *AuthUserSetter) error { + var err error + + authUser1, err := AuthUsers.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachAuthUserUserPermissionUserAuthUser0(ctx, exec, 1, authUserUserPermission0, authUser1) + if err != nil { + return err + } + + authUserUserPermission0.R.UserAuthUser = authUser1 + + authUser1.R.UserAuthUserUserPermissions = append(authUser1.R.UserAuthUserUserPermissions, authUserUserPermission0) + + return nil +} + +func (authUserUserPermission0 *AuthUserUserPermission) AttachUserAuthUser(ctx context.Context, exec bob.Executor, authUser1 *AuthUser) error { + var err error + + _, err = attachAuthUserUserPermissionUserAuthUser0(ctx, exec, 1, authUserUserPermission0, authUser1) + if err != nil { + return err + } + + authUserUserPermission0.R.UserAuthUser = authUser1 + + authUser1.R.UserAuthUserUserPermissions = append(authUser1.R.UserAuthUserUserPermissions, authUserUserPermission0) + + return nil +} + +type authUserUserPermissionWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UserID mysql.WhereMod[Q, int32] + PermissionID mysql.WhereMod[Q, int32] +} + +func (authUserUserPermissionWhere[Q]) AliasedAs(alias string) authUserUserPermissionWhere[Q] { + return buildAuthUserUserPermissionWhere[Q](buildAuthUserUserPermissionColumns(alias)) +} + +func buildAuthUserUserPermissionWhere[Q mysql.Filterable](cols authUserUserPermissionColumns) authUserUserPermissionWhere[Q] { + return authUserUserPermissionWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UserID: mysql.Where[Q, int32](cols.UserID), + PermissionID: mysql.Where[Q, int32](cols.PermissionID), + } +} + +func (o *AuthUserUserPermission) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "PermissionAuthPermission": + rel, ok := retrieved.(*AuthPermission) + if !ok { + return fmt.Errorf("authUserUserPermission cannot load %T as %q", retrieved, name) + } + + o.R.PermissionAuthPermission = rel + + if rel != nil { + rel.R.PermissionAuthUserUserPermissions = AuthUserUserPermissionSlice{o} + } + return nil + case "UserAuthUser": + rel, ok := retrieved.(*AuthUser) + if !ok { + return fmt.Errorf("authUserUserPermission cannot load %T as %q", retrieved, name) + } + + o.R.UserAuthUser = rel + + if rel != nil { + rel.R.UserAuthUserUserPermissions = AuthUserUserPermissionSlice{o} + } + return nil + default: + return fmt.Errorf("authUserUserPermission has no relationship %q", name) + } +} + +type authUserUserPermissionPreloader struct { + PermissionAuthPermission func(...mysql.PreloadOption) mysql.Preloader + UserAuthUser func(...mysql.PreloadOption) mysql.Preloader +} + +func buildAuthUserUserPermissionPreloader() authUserUserPermissionPreloader { + return authUserUserPermissionPreloader{ + PermissionAuthPermission: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthPermission, AuthPermissionSlice](mysql.PreloadRel{ + Name: "PermissionAuthPermission", + Sides: []mysql.PreloadSide{ + { + From: AuthUserUserPermissions, + To: AuthPermissions, + FromColumns: []string{"permission_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthPermissions.Columns.Names(), opts...) + }, + UserAuthUser: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthUser, AuthUserSlice](mysql.PreloadRel{ + Name: "UserAuthUser", + Sides: []mysql.PreloadSide{ + { + From: AuthUserUserPermissions, + To: AuthUsers, + FromColumns: []string{"user_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthUsers.Columns.Names(), opts...) + }, + } +} + +type authUserUserPermissionThenLoader[Q orm.Loadable] struct { + PermissionAuthPermission func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + UserAuthUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildAuthUserUserPermissionThenLoader[Q orm.Loadable]() authUserUserPermissionThenLoader[Q] { + type PermissionAuthPermissionLoadInterface interface { + LoadPermissionAuthPermission(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type UserAuthUserLoadInterface interface { + LoadUserAuthUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return authUserUserPermissionThenLoader[Q]{ + PermissionAuthPermission: thenLoadBuilder[Q]( + "PermissionAuthPermission", + func(ctx context.Context, exec bob.Executor, retrieved PermissionAuthPermissionLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPermissionAuthPermission(ctx, exec, mods...) + }, + ), + UserAuthUser: thenLoadBuilder[Q]( + "UserAuthUser", + func(ctx context.Context, exec bob.Executor, retrieved UserAuthUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUserAuthUser(ctx, exec, mods...) + }, + ), + } +} + +// LoadPermissionAuthPermission loads the authUserUserPermission's PermissionAuthPermission into the .R struct +func (o *AuthUserUserPermission) LoadPermissionAuthPermission(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PermissionAuthPermission = nil + + related, err := o.PermissionAuthPermission(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PermissionAuthUserUserPermissions = AuthUserUserPermissionSlice{o} + + o.R.PermissionAuthPermission = related + return nil +} + +// LoadPermissionAuthPermission loads the authUserUserPermission's PermissionAuthPermission into the .R struct +func (os AuthUserUserPermissionSlice) LoadPermissionAuthPermission(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authPermissions, err := os.PermissionAuthPermission(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authPermissions { + + if !(o.PermissionID == rel.ID) { + continue + } + + rel.R.PermissionAuthUserUserPermissions = append(rel.R.PermissionAuthUserUserPermissions, o) + + o.R.PermissionAuthPermission = rel + break + } + } + + return nil +} + +// LoadUserAuthUser loads the authUserUserPermission's UserAuthUser into the .R struct +func (o *AuthUserUserPermission) LoadUserAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UserAuthUser = nil + + related, err := o.UserAuthUser(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.UserAuthUserUserPermissions = AuthUserUserPermissionSlice{o} + + o.R.UserAuthUser = related + return nil +} + +// LoadUserAuthUser loads the authUserUserPermission's UserAuthUser into the .R struct +func (os AuthUserUserPermissionSlice) LoadUserAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUsers, err := os.UserAuthUser(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUsers { + + if !(o.UserID == rel.ID) { + continue + } + + rel.R.UserAuthUserUserPermissions = append(rel.R.UserAuthUserUserPermissions, o) + + o.R.UserAuthUser = rel + break + } + } + + return nil +} + +type authUserUserPermissionJoins[Q dialect.Joinable] struct { + typ string + PermissionAuthPermission modAs[Q, authPermissionColumns] + UserAuthUser modAs[Q, authUserColumns] +} + +func (j authUserUserPermissionJoins[Q]) aliasedAs(alias string) authUserUserPermissionJoins[Q] { + return buildAuthUserUserPermissionJoins[Q](buildAuthUserUserPermissionColumns(alias), j.typ) +} + +func buildAuthUserUserPermissionJoins[Q dialect.Joinable](cols authUserUserPermissionColumns, typ string) authUserUserPermissionJoins[Q] { + return authUserUserPermissionJoins[Q]{ + typ: typ, + PermissionAuthPermission: modAs[Q, authPermissionColumns]{ + c: AuthPermissions.Columns, + f: func(to authPermissionColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthPermissions.Name().As(to.Alias())).On( + to.ID.EQ(cols.PermissionID), + )) + } + + return mods + }, + }, + UserAuthUser: modAs[Q, authUserColumns]{ + c: AuthUsers.Columns, + f: func(to authUserColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUsers.Name().As(to.Alias())).On( + to.ID.EQ(cols.UserID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/bob_joins.bob.go b/database/mcp/models/bob_joins.bob.go new file mode 100644 index 0000000..cd067d6 --- /dev/null +++ b/database/mcp/models/bob_joins.bob.go @@ -0,0 +1,146 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "hash/maphash" + + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/clause" + "github.com/stephenafamo/bob/dialect/mysql/dialect" +) + +var ( + SelectJoins = getJoins[*dialect.SelectQuery]() + UpdateJoins = getJoins[*dialect.UpdateQuery]() + DeleteJoins = getJoins[*dialect.DeleteQuery]() +) + +type joinSet[Q interface{ aliasedAs(string) Q }] struct { + InnerJoin Q + LeftJoin Q + RightJoin Q +} + +func (j joinSet[Q]) AliasedAs(alias string) joinSet[Q] { + return joinSet[Q]{ + InnerJoin: j.InnerJoin.aliasedAs(alias), + LeftJoin: j.LeftJoin.aliasedAs(alias), + RightJoin: j.RightJoin.aliasedAs(alias), + } +} + +type joins[Q dialect.Joinable] struct { + AuthGroups joinSet[authGroupJoins[Q]] + AuthGroupPermissions joinSet[authGroupPermissionJoins[Q]] + AuthPermissions joinSet[authPermissionJoins[Q]] + AuthUsers joinSet[authUserJoins[Q]] + AuthUserGroups joinSet[authUserGroupJoins[Q]] + AuthUserUserPermissions joinSet[authUserUserPermissionJoins[Q]] + DjangoAdminLogs joinSet[djangoAdminLogJoins[Q]] + DjangoContentTypes joinSet[djangoContentTypeJoins[Q]] + LocationsArchipelagos joinSet[locationsArchipelagoJoins[Q]] + LocationsArkivums joinSet[locationsArkivumJoins[Q]] + LocationsDataverses joinSet[locationsDataverseJoins[Q]] + LocationsDspaces joinSet[locationsDspaceJoins[Q]] + LocationsDspacerests joinSet[locationsDspacerestJoins[Q]] + LocationsDuraclouds joinSet[locationsDuracloudJoins[Q]] + LocationsEvents joinSet[locationsEventJoins[Q]] + LocationsFedoras joinSet[locationsFedoraJoins[Q]] + LocationsFiles joinSet[locationsFileJoins[Q]] + LocationsFixitylogs joinSet[locationsFixitylogJoins[Q]] + LocationsGPGS joinSet[locationsGPGJoins[Q]] + LocationsLocalfilesystems joinSet[locationsLocalfilesystemJoins[Q]] + LocationsLocations joinSet[locationsLocationJoins[Q]] + LocationsLocationReplicators joinSet[locationsLocationReplicatorJoins[Q]] + LocationsLocationpipelines joinSet[locationsLocationpipelineJoins[Q]] + LocationsLockssomatics joinSet[locationsLockssomaticJoins[Q]] + LocationsNFS joinSet[locationsNFJoins[Q]] + LocationsOfflinereplicastagings joinSet[locationsOfflinereplicastagingJoins[Q]] + LocationsPackages joinSet[locationsPackageJoins[Q]] + LocationsPackageRelatedPackages joinSet[locationsPackageRelatedPackageJoins[Q]] + LocationsPackagedownloadtasks joinSet[locationsPackagedownloadtaskJoins[Q]] + LocationsPackagedownloadtaskfiles joinSet[locationsPackagedownloadtaskfileJoins[Q]] + LocationsPipelines joinSet[locationsPipelineJoins[Q]] + LocationsPipelinelocalfs joinSet[locationsPipelinelocalfJoins[Q]] + LocationsRclones joinSet[locationsRcloneJoins[Q]] + LocationsS3S joinSet[locationsS3Joins[Q]] + LocationsSpaces joinSet[locationsSpaceJoins[Q]] + LocationsSwifts joinSet[locationsSwiftJoins[Q]] + TastypieApikeys joinSet[tastypieApikeyJoins[Q]] +} + +func buildJoinSet[Q interface{ aliasedAs(string) Q }, C any, F func(C, string) Q](c C, f F) joinSet[Q] { + return joinSet[Q]{ + InnerJoin: f(c, clause.InnerJoin), + LeftJoin: f(c, clause.LeftJoin), + RightJoin: f(c, clause.RightJoin), + } +} + +func getJoins[Q dialect.Joinable]() joins[Q] { + return joins[Q]{ + AuthGroups: buildJoinSet[authGroupJoins[Q]](AuthGroups.Columns, buildAuthGroupJoins), + AuthGroupPermissions: buildJoinSet[authGroupPermissionJoins[Q]](AuthGroupPermissions.Columns, buildAuthGroupPermissionJoins), + AuthPermissions: buildJoinSet[authPermissionJoins[Q]](AuthPermissions.Columns, buildAuthPermissionJoins), + AuthUsers: buildJoinSet[authUserJoins[Q]](AuthUsers.Columns, buildAuthUserJoins), + AuthUserGroups: buildJoinSet[authUserGroupJoins[Q]](AuthUserGroups.Columns, buildAuthUserGroupJoins), + AuthUserUserPermissions: buildJoinSet[authUserUserPermissionJoins[Q]](AuthUserUserPermissions.Columns, buildAuthUserUserPermissionJoins), + DjangoAdminLogs: buildJoinSet[djangoAdminLogJoins[Q]](DjangoAdminLogs.Columns, buildDjangoAdminLogJoins), + DjangoContentTypes: buildJoinSet[djangoContentTypeJoins[Q]](DjangoContentTypes.Columns, buildDjangoContentTypeJoins), + LocationsArchipelagos: buildJoinSet[locationsArchipelagoJoins[Q]](LocationsArchipelagos.Columns, buildLocationsArchipelagoJoins), + LocationsArkivums: buildJoinSet[locationsArkivumJoins[Q]](LocationsArkivums.Columns, buildLocationsArkivumJoins), + LocationsDataverses: buildJoinSet[locationsDataverseJoins[Q]](LocationsDataverses.Columns, buildLocationsDataverseJoins), + LocationsDspaces: buildJoinSet[locationsDspaceJoins[Q]](LocationsDspaces.Columns, buildLocationsDspaceJoins), + LocationsDspacerests: buildJoinSet[locationsDspacerestJoins[Q]](LocationsDspacerests.Columns, buildLocationsDspacerestJoins), + LocationsDuraclouds: buildJoinSet[locationsDuracloudJoins[Q]](LocationsDuraclouds.Columns, buildLocationsDuracloudJoins), + LocationsEvents: buildJoinSet[locationsEventJoins[Q]](LocationsEvents.Columns, buildLocationsEventJoins), + LocationsFedoras: buildJoinSet[locationsFedoraJoins[Q]](LocationsFedoras.Columns, buildLocationsFedoraJoins), + LocationsFiles: buildJoinSet[locationsFileJoins[Q]](LocationsFiles.Columns, buildLocationsFileJoins), + LocationsFixitylogs: buildJoinSet[locationsFixitylogJoins[Q]](LocationsFixitylogs.Columns, buildLocationsFixitylogJoins), + LocationsGPGS: buildJoinSet[locationsGPGJoins[Q]](LocationsGPGS.Columns, buildLocationsGPGJoins), + LocationsLocalfilesystems: buildJoinSet[locationsLocalfilesystemJoins[Q]](LocationsLocalfilesystems.Columns, buildLocationsLocalfilesystemJoins), + LocationsLocations: buildJoinSet[locationsLocationJoins[Q]](LocationsLocations.Columns, buildLocationsLocationJoins), + LocationsLocationReplicators: buildJoinSet[locationsLocationReplicatorJoins[Q]](LocationsLocationReplicators.Columns, buildLocationsLocationReplicatorJoins), + LocationsLocationpipelines: buildJoinSet[locationsLocationpipelineJoins[Q]](LocationsLocationpipelines.Columns, buildLocationsLocationpipelineJoins), + LocationsLockssomatics: buildJoinSet[locationsLockssomaticJoins[Q]](LocationsLockssomatics.Columns, buildLocationsLockssomaticJoins), + LocationsNFS: buildJoinSet[locationsNFJoins[Q]](LocationsNFS.Columns, buildLocationsNFJoins), + LocationsOfflinereplicastagings: buildJoinSet[locationsOfflinereplicastagingJoins[Q]](LocationsOfflinereplicastagings.Columns, buildLocationsOfflinereplicastagingJoins), + LocationsPackages: buildJoinSet[locationsPackageJoins[Q]](LocationsPackages.Columns, buildLocationsPackageJoins), + LocationsPackageRelatedPackages: buildJoinSet[locationsPackageRelatedPackageJoins[Q]](LocationsPackageRelatedPackages.Columns, buildLocationsPackageRelatedPackageJoins), + LocationsPackagedownloadtasks: buildJoinSet[locationsPackagedownloadtaskJoins[Q]](LocationsPackagedownloadtasks.Columns, buildLocationsPackagedownloadtaskJoins), + LocationsPackagedownloadtaskfiles: buildJoinSet[locationsPackagedownloadtaskfileJoins[Q]](LocationsPackagedownloadtaskfiles.Columns, buildLocationsPackagedownloadtaskfileJoins), + LocationsPipelines: buildJoinSet[locationsPipelineJoins[Q]](LocationsPipelines.Columns, buildLocationsPipelineJoins), + LocationsPipelinelocalfs: buildJoinSet[locationsPipelinelocalfJoins[Q]](LocationsPipelinelocalfs.Columns, buildLocationsPipelinelocalfJoins), + LocationsRclones: buildJoinSet[locationsRcloneJoins[Q]](LocationsRclones.Columns, buildLocationsRcloneJoins), + LocationsS3S: buildJoinSet[locationsS3Joins[Q]](LocationsS3S.Columns, buildLocationsS3Joins), + LocationsSpaces: buildJoinSet[locationsSpaceJoins[Q]](LocationsSpaces.Columns, buildLocationsSpaceJoins), + LocationsSwifts: buildJoinSet[locationsSwiftJoins[Q]](LocationsSwifts.Columns, buildLocationsSwiftJoins), + TastypieApikeys: buildJoinSet[tastypieApikeyJoins[Q]](TastypieApikeys.Columns, buildTastypieApikeyJoins), + } +} + +type modAs[Q any, C interface{ AliasedAs(string) C }] struct { + c C + f func(C) bob.Mod[Q] +} + +func (m modAs[Q, C]) Apply(q Q) { + m.f(m.c).Apply(q) +} + +func (m modAs[Q, C]) AliasedAs(alias string) bob.Mod[Q] { + m.c = m.c.AliasedAs(alias) + return m +} + +func randInt() int64 { + out := int64(new(maphash.Hash).Sum64()) + + if out < 0 { + return -out % 10000 + } + + return out % 10000 +} diff --git a/database/mcp/models/bob_loaders.bob.go b/database/mcp/models/bob_loaders.bob.go new file mode 100644 index 0000000..bc15cec --- /dev/null +++ b/database/mcp/models/bob_loaders.bob.go @@ -0,0 +1,203 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "database/sql" + "errors" + "fmt" + + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/orm" +) + +var Preload = getPreloaders() + +type preloaders struct { + AuthGroup authGroupPreloader + AuthGroupPermission authGroupPermissionPreloader + AuthPermission authPermissionPreloader + AuthUser authUserPreloader + AuthUserGroup authUserGroupPreloader + AuthUserUserPermission authUserUserPermissionPreloader + DjangoAdminLog djangoAdminLogPreloader + DjangoContentType djangoContentTypePreloader + LocationsArchipelago locationsArchipelagoPreloader + LocationsArkivum locationsArkivumPreloader + LocationsDataverse locationsDataversePreloader + LocationsDspace locationsDspacePreloader + LocationsDspacerest locationsDspacerestPreloader + LocationsDuracloud locationsDuracloudPreloader + LocationsEvent locationsEventPreloader + LocationsFedora locationsFedoraPreloader + LocationsFile locationsFilePreloader + LocationsFixitylog locationsFixitylogPreloader + LocationsGPG locationsGPGPreloader + LocationsLocalfilesystem locationsLocalfilesystemPreloader + LocationsLocation locationsLocationPreloader + LocationsLocationReplicator locationsLocationReplicatorPreloader + LocationsLocationpipeline locationsLocationpipelinePreloader + LocationsLockssomatic locationsLockssomaticPreloader + LocationsNF locationsNFPreloader + LocationsOfflinereplicastaging locationsOfflinereplicastagingPreloader + LocationsPackage locationsPackagePreloader + LocationsPackageRelatedPackage locationsPackageRelatedPackagePreloader + LocationsPackagedownloadtask locationsPackagedownloadtaskPreloader + LocationsPackagedownloadtaskfile locationsPackagedownloadtaskfilePreloader + LocationsPipeline locationsPipelinePreloader + LocationsPipelinelocalf locationsPipelinelocalfPreloader + LocationsRclone locationsRclonePreloader + LocationsS3 locationsS3Preloader + LocationsSpace locationsSpacePreloader + LocationsSwift locationsSwiftPreloader + TastypieApikey tastypieApikeyPreloader +} + +func getPreloaders() preloaders { + return preloaders{ + AuthGroup: buildAuthGroupPreloader(), + AuthGroupPermission: buildAuthGroupPermissionPreloader(), + AuthPermission: buildAuthPermissionPreloader(), + AuthUser: buildAuthUserPreloader(), + AuthUserGroup: buildAuthUserGroupPreloader(), + AuthUserUserPermission: buildAuthUserUserPermissionPreloader(), + DjangoAdminLog: buildDjangoAdminLogPreloader(), + DjangoContentType: buildDjangoContentTypePreloader(), + LocationsArchipelago: buildLocationsArchipelagoPreloader(), + LocationsArkivum: buildLocationsArkivumPreloader(), + LocationsDataverse: buildLocationsDataversePreloader(), + LocationsDspace: buildLocationsDspacePreloader(), + LocationsDspacerest: buildLocationsDspacerestPreloader(), + LocationsDuracloud: buildLocationsDuracloudPreloader(), + LocationsEvent: buildLocationsEventPreloader(), + LocationsFedora: buildLocationsFedoraPreloader(), + LocationsFile: buildLocationsFilePreloader(), + LocationsFixitylog: buildLocationsFixitylogPreloader(), + LocationsGPG: buildLocationsGPGPreloader(), + LocationsLocalfilesystem: buildLocationsLocalfilesystemPreloader(), + LocationsLocation: buildLocationsLocationPreloader(), + LocationsLocationReplicator: buildLocationsLocationReplicatorPreloader(), + LocationsLocationpipeline: buildLocationsLocationpipelinePreloader(), + LocationsLockssomatic: buildLocationsLockssomaticPreloader(), + LocationsNF: buildLocationsNFPreloader(), + LocationsOfflinereplicastaging: buildLocationsOfflinereplicastagingPreloader(), + LocationsPackage: buildLocationsPackagePreloader(), + LocationsPackageRelatedPackage: buildLocationsPackageRelatedPackagePreloader(), + LocationsPackagedownloadtask: buildLocationsPackagedownloadtaskPreloader(), + LocationsPackagedownloadtaskfile: buildLocationsPackagedownloadtaskfilePreloader(), + LocationsPipeline: buildLocationsPipelinePreloader(), + LocationsPipelinelocalf: buildLocationsPipelinelocalfPreloader(), + LocationsRclone: buildLocationsRclonePreloader(), + LocationsS3: buildLocationsS3Preloader(), + LocationsSpace: buildLocationsSpacePreloader(), + LocationsSwift: buildLocationsSwiftPreloader(), + TastypieApikey: buildTastypieApikeyPreloader(), + } +} + +var SelectThenLoad = getThenLoaders[*dialect.SelectQuery]() + +type thenLoaders[Q orm.Loadable] struct { + AuthGroup authGroupThenLoader[Q] + AuthGroupPermission authGroupPermissionThenLoader[Q] + AuthPermission authPermissionThenLoader[Q] + AuthUser authUserThenLoader[Q] + AuthUserGroup authUserGroupThenLoader[Q] + AuthUserUserPermission authUserUserPermissionThenLoader[Q] + DjangoAdminLog djangoAdminLogThenLoader[Q] + DjangoContentType djangoContentTypeThenLoader[Q] + LocationsArchipelago locationsArchipelagoThenLoader[Q] + LocationsArkivum locationsArkivumThenLoader[Q] + LocationsDataverse locationsDataverseThenLoader[Q] + LocationsDspace locationsDspaceThenLoader[Q] + LocationsDspacerest locationsDspacerestThenLoader[Q] + LocationsDuracloud locationsDuracloudThenLoader[Q] + LocationsEvent locationsEventThenLoader[Q] + LocationsFedora locationsFedoraThenLoader[Q] + LocationsFile locationsFileThenLoader[Q] + LocationsFixitylog locationsFixitylogThenLoader[Q] + LocationsGPG locationsGPGThenLoader[Q] + LocationsLocalfilesystem locationsLocalfilesystemThenLoader[Q] + LocationsLocation locationsLocationThenLoader[Q] + LocationsLocationReplicator locationsLocationReplicatorThenLoader[Q] + LocationsLocationpipeline locationsLocationpipelineThenLoader[Q] + LocationsLockssomatic locationsLockssomaticThenLoader[Q] + LocationsNF locationsNFThenLoader[Q] + LocationsOfflinereplicastaging locationsOfflinereplicastagingThenLoader[Q] + LocationsPackage locationsPackageThenLoader[Q] + LocationsPackageRelatedPackage locationsPackageRelatedPackageThenLoader[Q] + LocationsPackagedownloadtask locationsPackagedownloadtaskThenLoader[Q] + LocationsPackagedownloadtaskfile locationsPackagedownloadtaskfileThenLoader[Q] + LocationsPipeline locationsPipelineThenLoader[Q] + LocationsPipelinelocalf locationsPipelinelocalfThenLoader[Q] + LocationsRclone locationsRcloneThenLoader[Q] + LocationsS3 locationsS3ThenLoader[Q] + LocationsSpace locationsSpaceThenLoader[Q] + LocationsSwift locationsSwiftThenLoader[Q] + TastypieApikey tastypieApikeyThenLoader[Q] +} + +func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] { + return thenLoaders[Q]{ + AuthGroup: buildAuthGroupThenLoader[Q](), + AuthGroupPermission: buildAuthGroupPermissionThenLoader[Q](), + AuthPermission: buildAuthPermissionThenLoader[Q](), + AuthUser: buildAuthUserThenLoader[Q](), + AuthUserGroup: buildAuthUserGroupThenLoader[Q](), + AuthUserUserPermission: buildAuthUserUserPermissionThenLoader[Q](), + DjangoAdminLog: buildDjangoAdminLogThenLoader[Q](), + DjangoContentType: buildDjangoContentTypeThenLoader[Q](), + LocationsArchipelago: buildLocationsArchipelagoThenLoader[Q](), + LocationsArkivum: buildLocationsArkivumThenLoader[Q](), + LocationsDataverse: buildLocationsDataverseThenLoader[Q](), + LocationsDspace: buildLocationsDspaceThenLoader[Q](), + LocationsDspacerest: buildLocationsDspacerestThenLoader[Q](), + LocationsDuracloud: buildLocationsDuracloudThenLoader[Q](), + LocationsEvent: buildLocationsEventThenLoader[Q](), + LocationsFedora: buildLocationsFedoraThenLoader[Q](), + LocationsFile: buildLocationsFileThenLoader[Q](), + LocationsFixitylog: buildLocationsFixitylogThenLoader[Q](), + LocationsGPG: buildLocationsGPGThenLoader[Q](), + LocationsLocalfilesystem: buildLocationsLocalfilesystemThenLoader[Q](), + LocationsLocation: buildLocationsLocationThenLoader[Q](), + LocationsLocationReplicator: buildLocationsLocationReplicatorThenLoader[Q](), + LocationsLocationpipeline: buildLocationsLocationpipelineThenLoader[Q](), + LocationsLockssomatic: buildLocationsLockssomaticThenLoader[Q](), + LocationsNF: buildLocationsNFThenLoader[Q](), + LocationsOfflinereplicastaging: buildLocationsOfflinereplicastagingThenLoader[Q](), + LocationsPackage: buildLocationsPackageThenLoader[Q](), + LocationsPackageRelatedPackage: buildLocationsPackageRelatedPackageThenLoader[Q](), + LocationsPackagedownloadtask: buildLocationsPackagedownloadtaskThenLoader[Q](), + LocationsPackagedownloadtaskfile: buildLocationsPackagedownloadtaskfileThenLoader[Q](), + LocationsPipeline: buildLocationsPipelineThenLoader[Q](), + LocationsPipelinelocalf: buildLocationsPipelinelocalfThenLoader[Q](), + LocationsRclone: buildLocationsRcloneThenLoader[Q](), + LocationsS3: buildLocationsS3ThenLoader[Q](), + LocationsSpace: buildLocationsSpaceThenLoader[Q](), + LocationsSwift: buildLocationsSwiftThenLoader[Q](), + TastypieApikey: buildTastypieApikeyThenLoader[Q](), + } +} + +func thenLoadBuilder[Q orm.Loadable, T any](name string, f func(context.Context, bob.Executor, T, ...bob.Mod[*dialect.SelectQuery]) error) func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] { + return func(queryMods ...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] { + return func(ctx context.Context, exec bob.Executor, retrieved any) error { + loader, isLoader := retrieved.(T) + if !isLoader { + return fmt.Errorf("object %T cannot load %q", retrieved, name) + } + + err := f(ctx, exec, loader, queryMods...) + + // Don't cause an issue due to missing relationships + if errors.Is(err, sql.ErrNoRows) { + return nil + } + + return err + } + } +} diff --git a/database/mcp/models/bob_types.bob_test.go b/database/mcp/models/bob_types.bob_test.go new file mode 100644 index 0000000..5dec749 --- /dev/null +++ b/database/mcp/models/bob_types.bob_test.go @@ -0,0 +1,141 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import "github.com/stephenafamo/bob" + +// Set the testDB to enable tests that use the database +var testDB bob.Transactor[bob.Tx] + +// Make sure the type AdministrationSetting runs hooks after queries +var _ bob.HookableType = &AdministrationSetting{} + +// Make sure the type AuthGroup runs hooks after queries +var _ bob.HookableType = &AuthGroup{} + +// Make sure the type AuthGroupPermission runs hooks after queries +var _ bob.HookableType = &AuthGroupPermission{} + +// Make sure the type AuthPermission runs hooks after queries +var _ bob.HookableType = &AuthPermission{} + +// Make sure the type AuthUser runs hooks after queries +var _ bob.HookableType = &AuthUser{} + +// Make sure the type AuthUserGroup runs hooks after queries +var _ bob.HookableType = &AuthUserGroup{} + +// Make sure the type AuthUserUserPermission runs hooks after queries +var _ bob.HookableType = &AuthUserUserPermission{} + +// Make sure the type DjangoAdminLog runs hooks after queries +var _ bob.HookableType = &DjangoAdminLog{} + +// Make sure the type DjangoContentType runs hooks after queries +var _ bob.HookableType = &DjangoContentType{} + +// Make sure the type DjangoMigration runs hooks after queries +var _ bob.HookableType = &DjangoMigration{} + +// Make sure the type DjangoSession runs hooks after queries +var _ bob.HookableType = &DjangoSession{} + +// Make sure the type DjangoSite runs hooks after queries +var _ bob.HookableType = &DjangoSite{} + +// Make sure the type LocationsArchipelago runs hooks after queries +var _ bob.HookableType = &LocationsArchipelago{} + +// Make sure the type LocationsArkivum runs hooks after queries +var _ bob.HookableType = &LocationsArkivum{} + +// Make sure the type LocationsAsync runs hooks after queries +var _ bob.HookableType = &LocationsAsync{} + +// Make sure the type LocationsCallback runs hooks after queries +var _ bob.HookableType = &LocationsCallback{} + +// Make sure the type LocationsDataverse runs hooks after queries +var _ bob.HookableType = &LocationsDataverse{} + +// Make sure the type LocationsDspace runs hooks after queries +var _ bob.HookableType = &LocationsDspace{} + +// Make sure the type LocationsDspacerest runs hooks after queries +var _ bob.HookableType = &LocationsDspacerest{} + +// Make sure the type LocationsDuracloud runs hooks after queries +var _ bob.HookableType = &LocationsDuracloud{} + +// Make sure the type LocationsEvent runs hooks after queries +var _ bob.HookableType = &LocationsEvent{} + +// Make sure the type LocationsFedora runs hooks after queries +var _ bob.HookableType = &LocationsFedora{} + +// Make sure the type LocationsFile runs hooks after queries +var _ bob.HookableType = &LocationsFile{} + +// Make sure the type LocationsFixitylog runs hooks after queries +var _ bob.HookableType = &LocationsFixitylog{} + +// Make sure the type LocationsGPG runs hooks after queries +var _ bob.HookableType = &LocationsGPG{} + +// Make sure the type LocationsLocalfilesystem runs hooks after queries +var _ bob.HookableType = &LocationsLocalfilesystem{} + +// Make sure the type LocationsLocation runs hooks after queries +var _ bob.HookableType = &LocationsLocation{} + +// Make sure the type LocationsLocationReplicator runs hooks after queries +var _ bob.HookableType = &LocationsLocationReplicator{} + +// Make sure the type LocationsLocationpipeline runs hooks after queries +var _ bob.HookableType = &LocationsLocationpipeline{} + +// Make sure the type LocationsLockssomatic runs hooks after queries +var _ bob.HookableType = &LocationsLockssomatic{} + +// Make sure the type LocationsNF runs hooks after queries +var _ bob.HookableType = &LocationsNF{} + +// Make sure the type LocationsOfflinereplicastaging runs hooks after queries +var _ bob.HookableType = &LocationsOfflinereplicastaging{} + +// Make sure the type LocationsPackage runs hooks after queries +var _ bob.HookableType = &LocationsPackage{} + +// Make sure the type LocationsPackageRelatedPackage runs hooks after queries +var _ bob.HookableType = &LocationsPackageRelatedPackage{} + +// Make sure the type LocationsPackagedownloadtask runs hooks after queries +var _ bob.HookableType = &LocationsPackagedownloadtask{} + +// Make sure the type LocationsPackagedownloadtaskfile runs hooks after queries +var _ bob.HookableType = &LocationsPackagedownloadtaskfile{} + +// Make sure the type LocationsPipeline runs hooks after queries +var _ bob.HookableType = &LocationsPipeline{} + +// Make sure the type LocationsPipelinelocalf runs hooks after queries +var _ bob.HookableType = &LocationsPipelinelocalf{} + +// Make sure the type LocationsRclone runs hooks after queries +var _ bob.HookableType = &LocationsRclone{} + +// Make sure the type LocationsS3 runs hooks after queries +var _ bob.HookableType = &LocationsS3{} + +// Make sure the type LocationsSpace runs hooks after queries +var _ bob.HookableType = &LocationsSpace{} + +// Make sure the type LocationsSwift runs hooks after queries +var _ bob.HookableType = &LocationsSwift{} + +// Make sure the type TastypieApiaccess runs hooks after queries +var _ bob.HookableType = &TastypieApiaccess{} + +// Make sure the type TastypieApikey runs hooks after queries +var _ bob.HookableType = &TastypieApikey{} diff --git a/database/mcp/models/bob_where.bob.go b/database/mcp/models/bob_where.bob.go new file mode 100644 index 0000000..aa26707 --- /dev/null +++ b/database/mcp/models/bob_where.bob.go @@ -0,0 +1,156 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "github.com/stephenafamo/bob/clause" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" +) + +var ( + SelectWhere = Where[*dialect.SelectQuery]() + UpdateWhere = Where[*dialect.UpdateQuery]() + DeleteWhere = Where[*dialect.DeleteQuery]() + OnConflictWhere = Where[*clause.ConflictClause]() // Used in ON CONFLICT DO UPDATE +) + +func Where[Q mysql.Filterable]() struct { + AdministrationSettings administrationSettingWhere[Q] + AuthGroups authGroupWhere[Q] + AuthGroupPermissions authGroupPermissionWhere[Q] + AuthPermissions authPermissionWhere[Q] + AuthUsers authUserWhere[Q] + AuthUserGroups authUserGroupWhere[Q] + AuthUserUserPermissions authUserUserPermissionWhere[Q] + DjangoAdminLogs djangoAdminLogWhere[Q] + DjangoContentTypes djangoContentTypeWhere[Q] + DjangoMigrations djangoMigrationWhere[Q] + DjangoSessions djangoSessionWhere[Q] + DjangoSites djangoSiteWhere[Q] + LocationsArchipelagos locationsArchipelagoWhere[Q] + LocationsArkivums locationsArkivumWhere[Q] + LocationsAsyncs locationsAsyncWhere[Q] + LocationsCallbacks locationsCallbackWhere[Q] + LocationsDataverses locationsDataverseWhere[Q] + LocationsDspaces locationsDspaceWhere[Q] + LocationsDspacerests locationsDspacerestWhere[Q] + LocationsDuraclouds locationsDuracloudWhere[Q] + LocationsEvents locationsEventWhere[Q] + LocationsFedoras locationsFedoraWhere[Q] + LocationsFiles locationsFileWhere[Q] + LocationsFixitylogs locationsFixitylogWhere[Q] + LocationsGPGS locationsGPGWhere[Q] + LocationsLocalfilesystems locationsLocalfilesystemWhere[Q] + LocationsLocations locationsLocationWhere[Q] + LocationsLocationReplicators locationsLocationReplicatorWhere[Q] + LocationsLocationpipelines locationsLocationpipelineWhere[Q] + LocationsLockssomatics locationsLockssomaticWhere[Q] + LocationsNFS locationsNFWhere[Q] + LocationsOfflinereplicastagings locationsOfflinereplicastagingWhere[Q] + LocationsPackages locationsPackageWhere[Q] + LocationsPackageRelatedPackages locationsPackageRelatedPackageWhere[Q] + LocationsPackagedownloadtasks locationsPackagedownloadtaskWhere[Q] + LocationsPackagedownloadtaskfiles locationsPackagedownloadtaskfileWhere[Q] + LocationsPipelines locationsPipelineWhere[Q] + LocationsPipelinelocalfs locationsPipelinelocalfWhere[Q] + LocationsRclones locationsRcloneWhere[Q] + LocationsS3S locationsS3Where[Q] + LocationsSpaces locationsSpaceWhere[Q] + LocationsSwifts locationsSwiftWhere[Q] + TastypieApiaccesses tastypieApiaccessWhere[Q] + TastypieApikeys tastypieApikeyWhere[Q] +} { + return struct { + AdministrationSettings administrationSettingWhere[Q] + AuthGroups authGroupWhere[Q] + AuthGroupPermissions authGroupPermissionWhere[Q] + AuthPermissions authPermissionWhere[Q] + AuthUsers authUserWhere[Q] + AuthUserGroups authUserGroupWhere[Q] + AuthUserUserPermissions authUserUserPermissionWhere[Q] + DjangoAdminLogs djangoAdminLogWhere[Q] + DjangoContentTypes djangoContentTypeWhere[Q] + DjangoMigrations djangoMigrationWhere[Q] + DjangoSessions djangoSessionWhere[Q] + DjangoSites djangoSiteWhere[Q] + LocationsArchipelagos locationsArchipelagoWhere[Q] + LocationsArkivums locationsArkivumWhere[Q] + LocationsAsyncs locationsAsyncWhere[Q] + LocationsCallbacks locationsCallbackWhere[Q] + LocationsDataverses locationsDataverseWhere[Q] + LocationsDspaces locationsDspaceWhere[Q] + LocationsDspacerests locationsDspacerestWhere[Q] + LocationsDuraclouds locationsDuracloudWhere[Q] + LocationsEvents locationsEventWhere[Q] + LocationsFedoras locationsFedoraWhere[Q] + LocationsFiles locationsFileWhere[Q] + LocationsFixitylogs locationsFixitylogWhere[Q] + LocationsGPGS locationsGPGWhere[Q] + LocationsLocalfilesystems locationsLocalfilesystemWhere[Q] + LocationsLocations locationsLocationWhere[Q] + LocationsLocationReplicators locationsLocationReplicatorWhere[Q] + LocationsLocationpipelines locationsLocationpipelineWhere[Q] + LocationsLockssomatics locationsLockssomaticWhere[Q] + LocationsNFS locationsNFWhere[Q] + LocationsOfflinereplicastagings locationsOfflinereplicastagingWhere[Q] + LocationsPackages locationsPackageWhere[Q] + LocationsPackageRelatedPackages locationsPackageRelatedPackageWhere[Q] + LocationsPackagedownloadtasks locationsPackagedownloadtaskWhere[Q] + LocationsPackagedownloadtaskfiles locationsPackagedownloadtaskfileWhere[Q] + LocationsPipelines locationsPipelineWhere[Q] + LocationsPipelinelocalfs locationsPipelinelocalfWhere[Q] + LocationsRclones locationsRcloneWhere[Q] + LocationsS3S locationsS3Where[Q] + LocationsSpaces locationsSpaceWhere[Q] + LocationsSwifts locationsSwiftWhere[Q] + TastypieApiaccesses tastypieApiaccessWhere[Q] + TastypieApikeys tastypieApikeyWhere[Q] + }{ + AdministrationSettings: buildAdministrationSettingWhere[Q](AdministrationSettings.Columns), + AuthGroups: buildAuthGroupWhere[Q](AuthGroups.Columns), + AuthGroupPermissions: buildAuthGroupPermissionWhere[Q](AuthGroupPermissions.Columns), + AuthPermissions: buildAuthPermissionWhere[Q](AuthPermissions.Columns), + AuthUsers: buildAuthUserWhere[Q](AuthUsers.Columns), + AuthUserGroups: buildAuthUserGroupWhere[Q](AuthUserGroups.Columns), + AuthUserUserPermissions: buildAuthUserUserPermissionWhere[Q](AuthUserUserPermissions.Columns), + DjangoAdminLogs: buildDjangoAdminLogWhere[Q](DjangoAdminLogs.Columns), + DjangoContentTypes: buildDjangoContentTypeWhere[Q](DjangoContentTypes.Columns), + DjangoMigrations: buildDjangoMigrationWhere[Q](DjangoMigrations.Columns), + DjangoSessions: buildDjangoSessionWhere[Q](DjangoSessions.Columns), + DjangoSites: buildDjangoSiteWhere[Q](DjangoSites.Columns), + LocationsArchipelagos: buildLocationsArchipelagoWhere[Q](LocationsArchipelagos.Columns), + LocationsArkivums: buildLocationsArkivumWhere[Q](LocationsArkivums.Columns), + LocationsAsyncs: buildLocationsAsyncWhere[Q](LocationsAsyncs.Columns), + LocationsCallbacks: buildLocationsCallbackWhere[Q](LocationsCallbacks.Columns), + LocationsDataverses: buildLocationsDataverseWhere[Q](LocationsDataverses.Columns), + LocationsDspaces: buildLocationsDspaceWhere[Q](LocationsDspaces.Columns), + LocationsDspacerests: buildLocationsDspacerestWhere[Q](LocationsDspacerests.Columns), + LocationsDuraclouds: buildLocationsDuracloudWhere[Q](LocationsDuraclouds.Columns), + LocationsEvents: buildLocationsEventWhere[Q](LocationsEvents.Columns), + LocationsFedoras: buildLocationsFedoraWhere[Q](LocationsFedoras.Columns), + LocationsFiles: buildLocationsFileWhere[Q](LocationsFiles.Columns), + LocationsFixitylogs: buildLocationsFixitylogWhere[Q](LocationsFixitylogs.Columns), + LocationsGPGS: buildLocationsGPGWhere[Q](LocationsGPGS.Columns), + LocationsLocalfilesystems: buildLocationsLocalfilesystemWhere[Q](LocationsLocalfilesystems.Columns), + LocationsLocations: buildLocationsLocationWhere[Q](LocationsLocations.Columns), + LocationsLocationReplicators: buildLocationsLocationReplicatorWhere[Q](LocationsLocationReplicators.Columns), + LocationsLocationpipelines: buildLocationsLocationpipelineWhere[Q](LocationsLocationpipelines.Columns), + LocationsLockssomatics: buildLocationsLockssomaticWhere[Q](LocationsLockssomatics.Columns), + LocationsNFS: buildLocationsNFWhere[Q](LocationsNFS.Columns), + LocationsOfflinereplicastagings: buildLocationsOfflinereplicastagingWhere[Q](LocationsOfflinereplicastagings.Columns), + LocationsPackages: buildLocationsPackageWhere[Q](LocationsPackages.Columns), + LocationsPackageRelatedPackages: buildLocationsPackageRelatedPackageWhere[Q](LocationsPackageRelatedPackages.Columns), + LocationsPackagedownloadtasks: buildLocationsPackagedownloadtaskWhere[Q](LocationsPackagedownloadtasks.Columns), + LocationsPackagedownloadtaskfiles: buildLocationsPackagedownloadtaskfileWhere[Q](LocationsPackagedownloadtaskfiles.Columns), + LocationsPipelines: buildLocationsPipelineWhere[Q](LocationsPipelines.Columns), + LocationsPipelinelocalfs: buildLocationsPipelinelocalfWhere[Q](LocationsPipelinelocalfs.Columns), + LocationsRclones: buildLocationsRcloneWhere[Q](LocationsRclones.Columns), + LocationsS3S: buildLocationsS3Where[Q](LocationsS3S.Columns), + LocationsSpaces: buildLocationsSpaceWhere[Q](LocationsSpaces.Columns), + LocationsSwifts: buildLocationsSwiftWhere[Q](LocationsSwifts.Columns), + TastypieApiaccesses: buildTastypieApiaccessWhere[Q](TastypieApiaccesses.Columns), + TastypieApikeys: buildTastypieApikeyWhere[Q](TastypieApikeys.Columns), + } +} diff --git a/database/mcp/models/django_admin_log.bob.go b/database/mcp/models/django_admin_log.bob.go new file mode 100644 index 0000000..7f6569c --- /dev/null +++ b/database/mcp/models/django_admin_log.bob.go @@ -0,0 +1,913 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// DjangoAdminLog is an object representing the database table. +type DjangoAdminLog struct { + ID int32 `db:"id,pk,autoincr" ` + ActionTime time.Time `db:"action_time" ` + ObjectID null.Val[string] `db:"object_id" ` + ObjectRepr string `db:"object_repr" ` + ActionFlag uint16 `db:"action_flag" ` + ChangeMessage string `db:"change_message" ` + ContentTypeID null.Val[int32] `db:"content_type_id" ` + UserID int32 `db:"user_id" ` + + R djangoAdminLogR `db:"-" ` +} + +// DjangoAdminLogSlice is an alias for a slice of pointers to DjangoAdminLog. +// This should almost always be used instead of []*DjangoAdminLog. +type DjangoAdminLogSlice []*DjangoAdminLog + +// DjangoAdminLogs contains methods to work with the django_admin_log table +var DjangoAdminLogs = mysql.NewTablex[*DjangoAdminLog, DjangoAdminLogSlice, *DjangoAdminLogSetter]("django_admin_log", buildDjangoAdminLogColumns("django_admin_log"), []string{"id"}) + +// DjangoAdminLogsQuery is a query on the django_admin_log table +type DjangoAdminLogsQuery = *mysql.ViewQuery[*DjangoAdminLog, DjangoAdminLogSlice] + +// djangoAdminLogR is where relationships are stored. +type djangoAdminLogR struct { + ContentTypeDjangoContentType *DjangoContentType // django_admin_log_content_type_id_c4bce8eb_fk_django_co + UserAuthUser *AuthUser // django_admin_log_user_id_c564eba6_fk_auth_user_id +} + +func buildDjangoAdminLogColumns(alias string) djangoAdminLogColumns { + return djangoAdminLogColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "action_time", "object_id", "object_repr", "action_flag", "change_message", "content_type_id", "user_id", + ).WithParent("django_admin_log"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + ActionTime: mysql.Quote(alias, "action_time"), + ObjectID: mysql.Quote(alias, "object_id"), + ObjectRepr: mysql.Quote(alias, "object_repr"), + ActionFlag: mysql.Quote(alias, "action_flag"), + ChangeMessage: mysql.Quote(alias, "change_message"), + ContentTypeID: mysql.Quote(alias, "content_type_id"), + UserID: mysql.Quote(alias, "user_id"), + } +} + +type djangoAdminLogColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + ActionTime mysql.Expression + ObjectID mysql.Expression + ObjectRepr mysql.Expression + ActionFlag mysql.Expression + ChangeMessage mysql.Expression + ContentTypeID mysql.Expression + UserID mysql.Expression +} + +func (c djangoAdminLogColumns) Alias() string { + return c.tableAlias +} + +func (djangoAdminLogColumns) AliasedAs(alias string) djangoAdminLogColumns { + return buildDjangoAdminLogColumns(alias) +} + +// DjangoAdminLogSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type DjangoAdminLogSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + ActionTime omit.Val[time.Time] `db:"action_time" ` + ObjectID omitnull.Val[string] `db:"object_id" ` + ObjectRepr omit.Val[string] `db:"object_repr" ` + ActionFlag omit.Val[uint16] `db:"action_flag" ` + ChangeMessage omit.Val[string] `db:"change_message" ` + ContentTypeID omitnull.Val[int32] `db:"content_type_id" ` + UserID omit.Val[int32] `db:"user_id" ` +} + +func (s DjangoAdminLogSetter) SetColumns() []string { + vals := make([]string, 0, 8) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.ActionTime.IsValue() { + vals = append(vals, "action_time") + } + if !s.ObjectID.IsUnset() { + vals = append(vals, "object_id") + } + if s.ObjectRepr.IsValue() { + vals = append(vals, "object_repr") + } + if s.ActionFlag.IsValue() { + vals = append(vals, "action_flag") + } + if s.ChangeMessage.IsValue() { + vals = append(vals, "change_message") + } + if !s.ContentTypeID.IsUnset() { + vals = append(vals, "content_type_id") + } + if s.UserID.IsValue() { + vals = append(vals, "user_id") + } + return vals +} + +func (s DjangoAdminLogSetter) Overwrite(t *DjangoAdminLog) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.ActionTime.IsValue() { + t.ActionTime = s.ActionTime.MustGet() + } + if !s.ObjectID.IsUnset() { + t.ObjectID = s.ObjectID.MustGetNull() + } + if s.ObjectRepr.IsValue() { + t.ObjectRepr = s.ObjectRepr.MustGet() + } + if s.ActionFlag.IsValue() { + t.ActionFlag = s.ActionFlag.MustGet() + } + if s.ChangeMessage.IsValue() { + t.ChangeMessage = s.ChangeMessage.MustGet() + } + if !s.ContentTypeID.IsUnset() { + t.ContentTypeID = s.ContentTypeID.MustGetNull() + } + if s.UserID.IsValue() { + t.UserID = s.UserID.MustGet() + } +} + +func (s *DjangoAdminLogSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoAdminLogs.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ActionTime.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ActionTime.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.ObjectID.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ObjectID.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ObjectRepr.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ObjectRepr.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ActionFlag.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ActionFlag.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ChangeMessage.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ChangeMessage.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.ContentTypeID.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ContentTypeID.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UserID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UserID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s DjangoAdminLogSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("django_admin_log")...) +} + +func (s DjangoAdminLogSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 8) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.ActionTime.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "action_time")...), + mysql.Arg(s.ActionTime), + }}) + } + + if !s.ObjectID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "object_id")...), + mysql.Arg(s.ObjectID), + }}) + } + + if s.ObjectRepr.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "object_repr")...), + mysql.Arg(s.ObjectRepr), + }}) + } + + if s.ActionFlag.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "action_flag")...), + mysql.Arg(s.ActionFlag), + }}) + } + + if s.ChangeMessage.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "change_message")...), + mysql.Arg(s.ChangeMessage), + }}) + } + + if !s.ContentTypeID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "content_type_id")...), + mysql.Arg(s.ContentTypeID), + }}) + } + + if s.UserID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "user_id")...), + mysql.Arg(s.UserID), + }}) + } + + return exprs +} + +// FindDjangoAdminLog retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindDjangoAdminLog(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*DjangoAdminLog, error) { + if len(cols) == 0 { + return DjangoAdminLogs.Query( + sm.Where(DjangoAdminLogs.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return DjangoAdminLogs.Query( + sm.Where(DjangoAdminLogs.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(DjangoAdminLogs.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// DjangoAdminLogExists checks the presence of a single record by primary key +func DjangoAdminLogExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return DjangoAdminLogs.Query( + sm.Where(DjangoAdminLogs.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after DjangoAdminLog is retrieved from the database +func (o *DjangoAdminLog) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoAdminLogs.AfterSelectHooks.RunHooks(ctx, exec, DjangoAdminLogSlice{o}) + case bob.QueryTypeInsert: + ctx, err = DjangoAdminLogs.AfterInsertHooks.RunHooks(ctx, exec, DjangoAdminLogSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = DjangoAdminLogs.AfterUpdateHooks.RunHooks(ctx, exec, DjangoAdminLogSlice{o}) + case bob.QueryTypeDelete: + ctx, err = DjangoAdminLogs.AfterDeleteHooks.RunHooks(ctx, exec, DjangoAdminLogSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the DjangoAdminLog +func (o *DjangoAdminLog) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *DjangoAdminLog) pkEQ() dialect.Expression { + return mysql.Quote("django_admin_log", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the DjangoAdminLog +func (o *DjangoAdminLog) Update(ctx context.Context, exec bob.Executor, s *DjangoAdminLogSetter) error { + _, err := DjangoAdminLogs.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single DjangoAdminLog record with an executor +func (o *DjangoAdminLog) Delete(ctx context.Context, exec bob.Executor) error { + _, err := DjangoAdminLogs.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the DjangoAdminLog using the executor +func (o *DjangoAdminLog) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := DjangoAdminLogs.Query( + sm.Where(DjangoAdminLogs.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after DjangoAdminLogSlice is retrieved from the database +func (o DjangoAdminLogSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoAdminLogs.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = DjangoAdminLogs.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = DjangoAdminLogs.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = DjangoAdminLogs.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o DjangoAdminLogSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("django_admin_log", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o DjangoAdminLogSlice) copyMatchingRows(from ...*DjangoAdminLog) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o DjangoAdminLogSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoAdminLogs.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoAdminLog: + o.copyMatchingRows(retrieved) + case []*DjangoAdminLog: + o.copyMatchingRows(retrieved...) + case DjangoAdminLogSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoAdminLog or a slice of DjangoAdminLog + // then run the AfterUpdateHooks on the slice + _, err = DjangoAdminLogs.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o DjangoAdminLogSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoAdminLogs.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoAdminLog: + o.copyMatchingRows(retrieved) + case []*DjangoAdminLog: + o.copyMatchingRows(retrieved...) + case DjangoAdminLogSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoAdminLog or a slice of DjangoAdminLog + // then run the AfterDeleteHooks on the slice + _, err = DjangoAdminLogs.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o DjangoAdminLogSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals DjangoAdminLogSetter) error { + _, err := DjangoAdminLogs.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o DjangoAdminLogSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := DjangoAdminLogs.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o DjangoAdminLogSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := DjangoAdminLogs.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// ContentTypeDjangoContentType starts a query for related objects on django_content_type +func (o *DjangoAdminLog) ContentTypeDjangoContentType(mods ...bob.Mod[*dialect.SelectQuery]) DjangoContentTypesQuery { + return DjangoContentTypes.Query(append(mods, + sm.Where(DjangoContentTypes.Columns.ID.EQ(mysql.Arg(o.ContentTypeID))), + )...) +} + +func (os DjangoAdminLogSlice) ContentTypeDjangoContentType(mods ...bob.Mod[*dialect.SelectQuery]) DjangoContentTypesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ContentTypeID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return DjangoContentTypes.Query(append(mods, + sm.Where(mysql.Group(DjangoContentTypes.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// UserAuthUser starts a query for related objects on auth_user +func (o *DjangoAdminLog) UserAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + return AuthUsers.Query(append(mods, + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(o.UserID))), + )...) +} + +func (os DjangoAdminLogSlice) UserAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UserID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUsers.Query(append(mods, + sm.Where(mysql.Group(AuthUsers.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func attachDjangoAdminLogContentTypeDjangoContentType0(ctx context.Context, exec bob.Executor, count int, djangoAdminLog0 *DjangoAdminLog, djangoContentType1 *DjangoContentType) (*DjangoAdminLog, error) { + setter := &DjangoAdminLogSetter{ + ContentTypeID: omitnull.From(djangoContentType1.ID), + } + + err := djangoAdminLog0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachDjangoAdminLogContentTypeDjangoContentType0: %w", err) + } + + return djangoAdminLog0, nil +} + +func (djangoAdminLog0 *DjangoAdminLog) InsertContentTypeDjangoContentType(ctx context.Context, exec bob.Executor, related *DjangoContentTypeSetter) error { + var err error + + djangoContentType1, err := DjangoContentTypes.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachDjangoAdminLogContentTypeDjangoContentType0(ctx, exec, 1, djangoAdminLog0, djangoContentType1) + if err != nil { + return err + } + + djangoAdminLog0.R.ContentTypeDjangoContentType = djangoContentType1 + + djangoContentType1.R.ContentTypeDjangoAdminLogs = append(djangoContentType1.R.ContentTypeDjangoAdminLogs, djangoAdminLog0) + + return nil +} + +func (djangoAdminLog0 *DjangoAdminLog) AttachContentTypeDjangoContentType(ctx context.Context, exec bob.Executor, djangoContentType1 *DjangoContentType) error { + var err error + + _, err = attachDjangoAdminLogContentTypeDjangoContentType0(ctx, exec, 1, djangoAdminLog0, djangoContentType1) + if err != nil { + return err + } + + djangoAdminLog0.R.ContentTypeDjangoContentType = djangoContentType1 + + djangoContentType1.R.ContentTypeDjangoAdminLogs = append(djangoContentType1.R.ContentTypeDjangoAdminLogs, djangoAdminLog0) + + return nil +} + +func attachDjangoAdminLogUserAuthUser0(ctx context.Context, exec bob.Executor, count int, djangoAdminLog0 *DjangoAdminLog, authUser1 *AuthUser) (*DjangoAdminLog, error) { + setter := &DjangoAdminLogSetter{ + UserID: omit.From(authUser1.ID), + } + + err := djangoAdminLog0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachDjangoAdminLogUserAuthUser0: %w", err) + } + + return djangoAdminLog0, nil +} + +func (djangoAdminLog0 *DjangoAdminLog) InsertUserAuthUser(ctx context.Context, exec bob.Executor, related *AuthUserSetter) error { + var err error + + authUser1, err := AuthUsers.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachDjangoAdminLogUserAuthUser0(ctx, exec, 1, djangoAdminLog0, authUser1) + if err != nil { + return err + } + + djangoAdminLog0.R.UserAuthUser = authUser1 + + authUser1.R.UserDjangoAdminLogs = append(authUser1.R.UserDjangoAdminLogs, djangoAdminLog0) + + return nil +} + +func (djangoAdminLog0 *DjangoAdminLog) AttachUserAuthUser(ctx context.Context, exec bob.Executor, authUser1 *AuthUser) error { + var err error + + _, err = attachDjangoAdminLogUserAuthUser0(ctx, exec, 1, djangoAdminLog0, authUser1) + if err != nil { + return err + } + + djangoAdminLog0.R.UserAuthUser = authUser1 + + authUser1.R.UserDjangoAdminLogs = append(authUser1.R.UserDjangoAdminLogs, djangoAdminLog0) + + return nil +} + +type djangoAdminLogWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + ActionTime mysql.WhereMod[Q, time.Time] + ObjectID mysql.WhereNullMod[Q, string] + ObjectRepr mysql.WhereMod[Q, string] + ActionFlag mysql.WhereMod[Q, uint16] + ChangeMessage mysql.WhereMod[Q, string] + ContentTypeID mysql.WhereNullMod[Q, int32] + UserID mysql.WhereMod[Q, int32] +} + +func (djangoAdminLogWhere[Q]) AliasedAs(alias string) djangoAdminLogWhere[Q] { + return buildDjangoAdminLogWhere[Q](buildDjangoAdminLogColumns(alias)) +} + +func buildDjangoAdminLogWhere[Q mysql.Filterable](cols djangoAdminLogColumns) djangoAdminLogWhere[Q] { + return djangoAdminLogWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + ActionTime: mysql.Where[Q, time.Time](cols.ActionTime), + ObjectID: mysql.WhereNull[Q, string](cols.ObjectID), + ObjectRepr: mysql.Where[Q, string](cols.ObjectRepr), + ActionFlag: mysql.Where[Q, uint16](cols.ActionFlag), + ChangeMessage: mysql.Where[Q, string](cols.ChangeMessage), + ContentTypeID: mysql.WhereNull[Q, int32](cols.ContentTypeID), + UserID: mysql.Where[Q, int32](cols.UserID), + } +} + +func (o *DjangoAdminLog) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "ContentTypeDjangoContentType": + rel, ok := retrieved.(*DjangoContentType) + if !ok { + return fmt.Errorf("djangoAdminLog cannot load %T as %q", retrieved, name) + } + + o.R.ContentTypeDjangoContentType = rel + + if rel != nil { + rel.R.ContentTypeDjangoAdminLogs = DjangoAdminLogSlice{o} + } + return nil + case "UserAuthUser": + rel, ok := retrieved.(*AuthUser) + if !ok { + return fmt.Errorf("djangoAdminLog cannot load %T as %q", retrieved, name) + } + + o.R.UserAuthUser = rel + + if rel != nil { + rel.R.UserDjangoAdminLogs = DjangoAdminLogSlice{o} + } + return nil + default: + return fmt.Errorf("djangoAdminLog has no relationship %q", name) + } +} + +type djangoAdminLogPreloader struct { + ContentTypeDjangoContentType func(...mysql.PreloadOption) mysql.Preloader + UserAuthUser func(...mysql.PreloadOption) mysql.Preloader +} + +func buildDjangoAdminLogPreloader() djangoAdminLogPreloader { + return djangoAdminLogPreloader{ + ContentTypeDjangoContentType: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*DjangoContentType, DjangoContentTypeSlice](mysql.PreloadRel{ + Name: "ContentTypeDjangoContentType", + Sides: []mysql.PreloadSide{ + { + From: DjangoAdminLogs, + To: DjangoContentTypes, + FromColumns: []string{"content_type_id"}, + ToColumns: []string{"id"}, + }, + }, + }, DjangoContentTypes.Columns.Names(), opts...) + }, + UserAuthUser: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthUser, AuthUserSlice](mysql.PreloadRel{ + Name: "UserAuthUser", + Sides: []mysql.PreloadSide{ + { + From: DjangoAdminLogs, + To: AuthUsers, + FromColumns: []string{"user_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthUsers.Columns.Names(), opts...) + }, + } +} + +type djangoAdminLogThenLoader[Q orm.Loadable] struct { + ContentTypeDjangoContentType func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + UserAuthUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildDjangoAdminLogThenLoader[Q orm.Loadable]() djangoAdminLogThenLoader[Q] { + type ContentTypeDjangoContentTypeLoadInterface interface { + LoadContentTypeDjangoContentType(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type UserAuthUserLoadInterface interface { + LoadUserAuthUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return djangoAdminLogThenLoader[Q]{ + ContentTypeDjangoContentType: thenLoadBuilder[Q]( + "ContentTypeDjangoContentType", + func(ctx context.Context, exec bob.Executor, retrieved ContentTypeDjangoContentTypeLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadContentTypeDjangoContentType(ctx, exec, mods...) + }, + ), + UserAuthUser: thenLoadBuilder[Q]( + "UserAuthUser", + func(ctx context.Context, exec bob.Executor, retrieved UserAuthUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUserAuthUser(ctx, exec, mods...) + }, + ), + } +} + +// LoadContentTypeDjangoContentType loads the djangoAdminLog's ContentTypeDjangoContentType into the .R struct +func (o *DjangoAdminLog) LoadContentTypeDjangoContentType(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ContentTypeDjangoContentType = nil + + related, err := o.ContentTypeDjangoContentType(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.ContentTypeDjangoAdminLogs = DjangoAdminLogSlice{o} + + o.R.ContentTypeDjangoContentType = related + return nil +} + +// LoadContentTypeDjangoContentType loads the djangoAdminLog's ContentTypeDjangoContentType into the .R struct +func (os DjangoAdminLogSlice) LoadContentTypeDjangoContentType(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + djangoContentTypes, err := os.ContentTypeDjangoContentType(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range djangoContentTypes { + if !o.ContentTypeID.IsValue() { + continue + } + + if !(o.ContentTypeID.IsValue() && o.ContentTypeID.MustGet() == rel.ID) { + continue + } + + rel.R.ContentTypeDjangoAdminLogs = append(rel.R.ContentTypeDjangoAdminLogs, o) + + o.R.ContentTypeDjangoContentType = rel + break + } + } + + return nil +} + +// LoadUserAuthUser loads the djangoAdminLog's UserAuthUser into the .R struct +func (o *DjangoAdminLog) LoadUserAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UserAuthUser = nil + + related, err := o.UserAuthUser(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.UserDjangoAdminLogs = DjangoAdminLogSlice{o} + + o.R.UserAuthUser = related + return nil +} + +// LoadUserAuthUser loads the djangoAdminLog's UserAuthUser into the .R struct +func (os DjangoAdminLogSlice) LoadUserAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUsers, err := os.UserAuthUser(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUsers { + + if !(o.UserID == rel.ID) { + continue + } + + rel.R.UserDjangoAdminLogs = append(rel.R.UserDjangoAdminLogs, o) + + o.R.UserAuthUser = rel + break + } + } + + return nil +} + +type djangoAdminLogJoins[Q dialect.Joinable] struct { + typ string + ContentTypeDjangoContentType modAs[Q, djangoContentTypeColumns] + UserAuthUser modAs[Q, authUserColumns] +} + +func (j djangoAdminLogJoins[Q]) aliasedAs(alias string) djangoAdminLogJoins[Q] { + return buildDjangoAdminLogJoins[Q](buildDjangoAdminLogColumns(alias), j.typ) +} + +func buildDjangoAdminLogJoins[Q dialect.Joinable](cols djangoAdminLogColumns, typ string) djangoAdminLogJoins[Q] { + return djangoAdminLogJoins[Q]{ + typ: typ, + ContentTypeDjangoContentType: modAs[Q, djangoContentTypeColumns]{ + c: DjangoContentTypes.Columns, + f: func(to djangoContentTypeColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, DjangoContentTypes.Name().As(to.Alias())).On( + to.ID.EQ(cols.ContentTypeID), + )) + } + + return mods + }, + }, + UserAuthUser: modAs[Q, authUserColumns]{ + c: AuthUsers.Columns, + f: func(to authUserColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUsers.Name().As(to.Alias())).On( + to.ID.EQ(cols.UserID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/django_content_type.bob.go b/database/mcp/models/django_content_type.bob.go new file mode 100644 index 0000000..7e90346 --- /dev/null +++ b/database/mcp/models/django_content_type.bob.go @@ -0,0 +1,823 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// DjangoContentType is an object representing the database table. +type DjangoContentType struct { + ID int32 `db:"id,pk,autoincr" ` + AppLabel string `db:"app_label" ` + Model string `db:"model" ` + + R djangoContentTypeR `db:"-" ` +} + +// DjangoContentTypeSlice is an alias for a slice of pointers to DjangoContentType. +// This should almost always be used instead of []*DjangoContentType. +type DjangoContentTypeSlice []*DjangoContentType + +// DjangoContentTypes contains methods to work with the django_content_type table +var DjangoContentTypes = mysql.NewTablex[*DjangoContentType, DjangoContentTypeSlice, *DjangoContentTypeSetter]("django_content_type", buildDjangoContentTypeColumns("django_content_type"), []string{"id"}, []string{"app_label", "model"}) + +// DjangoContentTypesQuery is a query on the django_content_type table +type DjangoContentTypesQuery = *mysql.ViewQuery[*DjangoContentType, DjangoContentTypeSlice] + +// djangoContentTypeR is where relationships are stored. +type djangoContentTypeR struct { + ContentTypeAuthPermissions AuthPermissionSlice // auth_permission_content_type_id_2f476e4b_fk_django_co + ContentTypeDjangoAdminLogs DjangoAdminLogSlice // django_admin_log_content_type_id_c4bce8eb_fk_django_co +} + +func buildDjangoContentTypeColumns(alias string) djangoContentTypeColumns { + return djangoContentTypeColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "app_label", "model", + ).WithParent("django_content_type"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + AppLabel: mysql.Quote(alias, "app_label"), + Model: mysql.Quote(alias, "model"), + } +} + +type djangoContentTypeColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + AppLabel mysql.Expression + Model mysql.Expression +} + +func (c djangoContentTypeColumns) Alias() string { + return c.tableAlias +} + +func (djangoContentTypeColumns) AliasedAs(alias string) djangoContentTypeColumns { + return buildDjangoContentTypeColumns(alias) +} + +// DjangoContentTypeSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type DjangoContentTypeSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + AppLabel omit.Val[string] `db:"app_label" ` + Model omit.Val[string] `db:"model" ` +} + +func (s DjangoContentTypeSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.AppLabel.IsValue() { + vals = append(vals, "app_label") + } + if s.Model.IsValue() { + vals = append(vals, "model") + } + return vals +} + +func (s DjangoContentTypeSetter) Overwrite(t *DjangoContentType) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.AppLabel.IsValue() { + t.AppLabel = s.AppLabel.MustGet() + } + if s.Model.IsValue() { + t.Model = s.Model.MustGet() + } +} + +func (s *DjangoContentTypeSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoContentTypes.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AppLabel.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AppLabel.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Model.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Model.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s DjangoContentTypeSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("django_content_type")...) +} + +func (s DjangoContentTypeSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.AppLabel.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "app_label")...), + mysql.Arg(s.AppLabel), + }}) + } + + if s.Model.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "model")...), + mysql.Arg(s.Model), + }}) + } + + return exprs +} + +// FindDjangoContentType retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindDjangoContentType(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*DjangoContentType, error) { + if len(cols) == 0 { + return DjangoContentTypes.Query( + sm.Where(DjangoContentTypes.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return DjangoContentTypes.Query( + sm.Where(DjangoContentTypes.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(DjangoContentTypes.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// DjangoContentTypeExists checks the presence of a single record by primary key +func DjangoContentTypeExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return DjangoContentTypes.Query( + sm.Where(DjangoContentTypes.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after DjangoContentType is retrieved from the database +func (o *DjangoContentType) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoContentTypes.AfterSelectHooks.RunHooks(ctx, exec, DjangoContentTypeSlice{o}) + case bob.QueryTypeInsert: + ctx, err = DjangoContentTypes.AfterInsertHooks.RunHooks(ctx, exec, DjangoContentTypeSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = DjangoContentTypes.AfterUpdateHooks.RunHooks(ctx, exec, DjangoContentTypeSlice{o}) + case bob.QueryTypeDelete: + ctx, err = DjangoContentTypes.AfterDeleteHooks.RunHooks(ctx, exec, DjangoContentTypeSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the DjangoContentType +func (o *DjangoContentType) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *DjangoContentType) pkEQ() dialect.Expression { + return mysql.Quote("django_content_type", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the DjangoContentType +func (o *DjangoContentType) Update(ctx context.Context, exec bob.Executor, s *DjangoContentTypeSetter) error { + _, err := DjangoContentTypes.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single DjangoContentType record with an executor +func (o *DjangoContentType) Delete(ctx context.Context, exec bob.Executor) error { + _, err := DjangoContentTypes.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the DjangoContentType using the executor +func (o *DjangoContentType) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := DjangoContentTypes.Query( + sm.Where(DjangoContentTypes.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after DjangoContentTypeSlice is retrieved from the database +func (o DjangoContentTypeSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoContentTypes.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = DjangoContentTypes.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = DjangoContentTypes.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = DjangoContentTypes.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o DjangoContentTypeSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("django_content_type", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o DjangoContentTypeSlice) copyMatchingRows(from ...*DjangoContentType) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o DjangoContentTypeSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoContentTypes.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoContentType: + o.copyMatchingRows(retrieved) + case []*DjangoContentType: + o.copyMatchingRows(retrieved...) + case DjangoContentTypeSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoContentType or a slice of DjangoContentType + // then run the AfterUpdateHooks on the slice + _, err = DjangoContentTypes.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o DjangoContentTypeSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoContentTypes.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoContentType: + o.copyMatchingRows(retrieved) + case []*DjangoContentType: + o.copyMatchingRows(retrieved...) + case DjangoContentTypeSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoContentType or a slice of DjangoContentType + // then run the AfterDeleteHooks on the slice + _, err = DjangoContentTypes.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o DjangoContentTypeSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals DjangoContentTypeSetter) error { + _, err := DjangoContentTypes.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o DjangoContentTypeSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := DjangoContentTypes.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o DjangoContentTypeSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := DjangoContentTypes.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// ContentTypeAuthPermissions starts a query for related objects on auth_permission +func (o *DjangoContentType) ContentTypeAuthPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthPermissionsQuery { + return AuthPermissions.Query(append(mods, + sm.Where(AuthPermissions.Columns.ContentTypeID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os DjangoContentTypeSlice) ContentTypeAuthPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthPermissionsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthPermissions.Query(append(mods, + sm.Where(mysql.Group(AuthPermissions.Columns.ContentTypeID).OP("IN", PKArgExpr)), + )...) +} + +// ContentTypeDjangoAdminLogs starts a query for related objects on django_admin_log +func (o *DjangoContentType) ContentTypeDjangoAdminLogs(mods ...bob.Mod[*dialect.SelectQuery]) DjangoAdminLogsQuery { + return DjangoAdminLogs.Query(append(mods, + sm.Where(DjangoAdminLogs.Columns.ContentTypeID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os DjangoContentTypeSlice) ContentTypeDjangoAdminLogs(mods ...bob.Mod[*dialect.SelectQuery]) DjangoAdminLogsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return DjangoAdminLogs.Query(append(mods, + sm.Where(mysql.Group(DjangoAdminLogs.Columns.ContentTypeID).OP("IN", PKArgExpr)), + )...) +} + +func insertDjangoContentTypeContentTypeAuthPermissions0(ctx context.Context, exec bob.Executor, authPermissions1 []*AuthPermissionSetter, djangoContentType0 *DjangoContentType) (AuthPermissionSlice, error) { + for i := range authPermissions1 { + authPermissions1[i].ContentTypeID = omit.From(djangoContentType0.ID) + } + + ret, err := AuthPermissions.Insert(bob.ToMods(authPermissions1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertDjangoContentTypeContentTypeAuthPermissions0: %w", err) + } + + return ret, nil +} + +func attachDjangoContentTypeContentTypeAuthPermissions0(ctx context.Context, exec bob.Executor, count int, authPermissions1 AuthPermissionSlice, djangoContentType0 *DjangoContentType) (AuthPermissionSlice, error) { + setter := &AuthPermissionSetter{ + ContentTypeID: omit.From(djangoContentType0.ID), + } + + err := authPermissions1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachDjangoContentTypeContentTypeAuthPermissions0: %w", err) + } + + return authPermissions1, nil +} + +func (djangoContentType0 *DjangoContentType) InsertContentTypeAuthPermissions(ctx context.Context, exec bob.Executor, related ...*AuthPermissionSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + authPermissions1, err := insertDjangoContentTypeContentTypeAuthPermissions0(ctx, exec, related, djangoContentType0) + if err != nil { + return err + } + + djangoContentType0.R.ContentTypeAuthPermissions = append(djangoContentType0.R.ContentTypeAuthPermissions, authPermissions1...) + + for _, rel := range authPermissions1 { + rel.R.ContentTypeDjangoContentType = djangoContentType0 + } + return nil +} + +func (djangoContentType0 *DjangoContentType) AttachContentTypeAuthPermissions(ctx context.Context, exec bob.Executor, related ...*AuthPermission) error { + if len(related) == 0 { + return nil + } + + var err error + authPermissions1 := AuthPermissionSlice(related) + + _, err = attachDjangoContentTypeContentTypeAuthPermissions0(ctx, exec, len(related), authPermissions1, djangoContentType0) + if err != nil { + return err + } + + djangoContentType0.R.ContentTypeAuthPermissions = append(djangoContentType0.R.ContentTypeAuthPermissions, authPermissions1...) + + for _, rel := range related { + rel.R.ContentTypeDjangoContentType = djangoContentType0 + } + + return nil +} + +func insertDjangoContentTypeContentTypeDjangoAdminLogs0(ctx context.Context, exec bob.Executor, djangoAdminLogs1 []*DjangoAdminLogSetter, djangoContentType0 *DjangoContentType) (DjangoAdminLogSlice, error) { + for i := range djangoAdminLogs1 { + djangoAdminLogs1[i].ContentTypeID = omitnull.From(djangoContentType0.ID) + } + + ret, err := DjangoAdminLogs.Insert(bob.ToMods(djangoAdminLogs1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertDjangoContentTypeContentTypeDjangoAdminLogs0: %w", err) + } + + return ret, nil +} + +func attachDjangoContentTypeContentTypeDjangoAdminLogs0(ctx context.Context, exec bob.Executor, count int, djangoAdminLogs1 DjangoAdminLogSlice, djangoContentType0 *DjangoContentType) (DjangoAdminLogSlice, error) { + setter := &DjangoAdminLogSetter{ + ContentTypeID: omitnull.From(djangoContentType0.ID), + } + + err := djangoAdminLogs1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachDjangoContentTypeContentTypeDjangoAdminLogs0: %w", err) + } + + return djangoAdminLogs1, nil +} + +func (djangoContentType0 *DjangoContentType) InsertContentTypeDjangoAdminLogs(ctx context.Context, exec bob.Executor, related ...*DjangoAdminLogSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + djangoAdminLogs1, err := insertDjangoContentTypeContentTypeDjangoAdminLogs0(ctx, exec, related, djangoContentType0) + if err != nil { + return err + } + + djangoContentType0.R.ContentTypeDjangoAdminLogs = append(djangoContentType0.R.ContentTypeDjangoAdminLogs, djangoAdminLogs1...) + + for _, rel := range djangoAdminLogs1 { + rel.R.ContentTypeDjangoContentType = djangoContentType0 + } + return nil +} + +func (djangoContentType0 *DjangoContentType) AttachContentTypeDjangoAdminLogs(ctx context.Context, exec bob.Executor, related ...*DjangoAdminLog) error { + if len(related) == 0 { + return nil + } + + var err error + djangoAdminLogs1 := DjangoAdminLogSlice(related) + + _, err = attachDjangoContentTypeContentTypeDjangoAdminLogs0(ctx, exec, len(related), djangoAdminLogs1, djangoContentType0) + if err != nil { + return err + } + + djangoContentType0.R.ContentTypeDjangoAdminLogs = append(djangoContentType0.R.ContentTypeDjangoAdminLogs, djangoAdminLogs1...) + + for _, rel := range related { + rel.R.ContentTypeDjangoContentType = djangoContentType0 + } + + return nil +} + +type djangoContentTypeWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + AppLabel mysql.WhereMod[Q, string] + Model mysql.WhereMod[Q, string] +} + +func (djangoContentTypeWhere[Q]) AliasedAs(alias string) djangoContentTypeWhere[Q] { + return buildDjangoContentTypeWhere[Q](buildDjangoContentTypeColumns(alias)) +} + +func buildDjangoContentTypeWhere[Q mysql.Filterable](cols djangoContentTypeColumns) djangoContentTypeWhere[Q] { + return djangoContentTypeWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + AppLabel: mysql.Where[Q, string](cols.AppLabel), + Model: mysql.Where[Q, string](cols.Model), + } +} + +func (o *DjangoContentType) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "ContentTypeAuthPermissions": + rels, ok := retrieved.(AuthPermissionSlice) + if !ok { + return fmt.Errorf("djangoContentType cannot load %T as %q", retrieved, name) + } + + o.R.ContentTypeAuthPermissions = rels + + for _, rel := range rels { + if rel != nil { + rel.R.ContentTypeDjangoContentType = o + } + } + return nil + case "ContentTypeDjangoAdminLogs": + rels, ok := retrieved.(DjangoAdminLogSlice) + if !ok { + return fmt.Errorf("djangoContentType cannot load %T as %q", retrieved, name) + } + + o.R.ContentTypeDjangoAdminLogs = rels + + for _, rel := range rels { + if rel != nil { + rel.R.ContentTypeDjangoContentType = o + } + } + return nil + default: + return fmt.Errorf("djangoContentType has no relationship %q", name) + } +} + +type djangoContentTypePreloader struct{} + +func buildDjangoContentTypePreloader() djangoContentTypePreloader { + return djangoContentTypePreloader{} +} + +type djangoContentTypeThenLoader[Q orm.Loadable] struct { + ContentTypeAuthPermissions func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ContentTypeDjangoAdminLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildDjangoContentTypeThenLoader[Q orm.Loadable]() djangoContentTypeThenLoader[Q] { + type ContentTypeAuthPermissionsLoadInterface interface { + LoadContentTypeAuthPermissions(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ContentTypeDjangoAdminLogsLoadInterface interface { + LoadContentTypeDjangoAdminLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return djangoContentTypeThenLoader[Q]{ + ContentTypeAuthPermissions: thenLoadBuilder[Q]( + "ContentTypeAuthPermissions", + func(ctx context.Context, exec bob.Executor, retrieved ContentTypeAuthPermissionsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadContentTypeAuthPermissions(ctx, exec, mods...) + }, + ), + ContentTypeDjangoAdminLogs: thenLoadBuilder[Q]( + "ContentTypeDjangoAdminLogs", + func(ctx context.Context, exec bob.Executor, retrieved ContentTypeDjangoAdminLogsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadContentTypeDjangoAdminLogs(ctx, exec, mods...) + }, + ), + } +} + +// LoadContentTypeAuthPermissions loads the djangoContentType's ContentTypeAuthPermissions into the .R struct +func (o *DjangoContentType) LoadContentTypeAuthPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ContentTypeAuthPermissions = nil + + related, err := o.ContentTypeAuthPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.ContentTypeDjangoContentType = o + } + + o.R.ContentTypeAuthPermissions = related + return nil +} + +// LoadContentTypeAuthPermissions loads the djangoContentType's ContentTypeAuthPermissions into the .R struct +func (os DjangoContentTypeSlice) LoadContentTypeAuthPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authPermissions, err := os.ContentTypeAuthPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.ContentTypeAuthPermissions = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authPermissions { + + if !(o.ID == rel.ContentTypeID) { + continue + } + + rel.R.ContentTypeDjangoContentType = o + + o.R.ContentTypeAuthPermissions = append(o.R.ContentTypeAuthPermissions, rel) + } + } + + return nil +} + +// LoadContentTypeDjangoAdminLogs loads the djangoContentType's ContentTypeDjangoAdminLogs into the .R struct +func (o *DjangoContentType) LoadContentTypeDjangoAdminLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ContentTypeDjangoAdminLogs = nil + + related, err := o.ContentTypeDjangoAdminLogs(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.ContentTypeDjangoContentType = o + } + + o.R.ContentTypeDjangoAdminLogs = related + return nil +} + +// LoadContentTypeDjangoAdminLogs loads the djangoContentType's ContentTypeDjangoAdminLogs into the .R struct +func (os DjangoContentTypeSlice) LoadContentTypeDjangoAdminLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + djangoAdminLogs, err := os.ContentTypeDjangoAdminLogs(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.ContentTypeDjangoAdminLogs = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range djangoAdminLogs { + + if !rel.ContentTypeID.IsValue() { + continue + } + if !(rel.ContentTypeID.IsValue() && o.ID == rel.ContentTypeID.MustGet()) { + continue + } + + rel.R.ContentTypeDjangoContentType = o + + o.R.ContentTypeDjangoAdminLogs = append(o.R.ContentTypeDjangoAdminLogs, rel) + } + } + + return nil +} + +type djangoContentTypeJoins[Q dialect.Joinable] struct { + typ string + ContentTypeAuthPermissions modAs[Q, authPermissionColumns] + ContentTypeDjangoAdminLogs modAs[Q, djangoAdminLogColumns] +} + +func (j djangoContentTypeJoins[Q]) aliasedAs(alias string) djangoContentTypeJoins[Q] { + return buildDjangoContentTypeJoins[Q](buildDjangoContentTypeColumns(alias), j.typ) +} + +func buildDjangoContentTypeJoins[Q dialect.Joinable](cols djangoContentTypeColumns, typ string) djangoContentTypeJoins[Q] { + return djangoContentTypeJoins[Q]{ + typ: typ, + ContentTypeAuthPermissions: modAs[Q, authPermissionColumns]{ + c: AuthPermissions.Columns, + f: func(to authPermissionColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthPermissions.Name().As(to.Alias())).On( + to.ContentTypeID.EQ(cols.ID), + )) + } + + return mods + }, + }, + ContentTypeDjangoAdminLogs: modAs[Q, djangoAdminLogColumns]{ + c: DjangoAdminLogs.Columns, + f: func(to djangoAdminLogColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, DjangoAdminLogs.Name().As(to.Alias())).On( + to.ContentTypeID.EQ(cols.ID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/django_migrations.bob.go b/database/mcp/models/django_migrations.bob.go new file mode 100644 index 0000000..df0e33f --- /dev/null +++ b/database/mcp/models/django_migrations.bob.go @@ -0,0 +1,419 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "io" + "time" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" +) + +// DjangoMigration is an object representing the database table. +type DjangoMigration struct { + ID int32 `db:"id,pk,autoincr" ` + App string `db:"app" ` + Name string `db:"name" ` + Applied time.Time `db:"applied" ` +} + +// DjangoMigrationSlice is an alias for a slice of pointers to DjangoMigration. +// This should almost always be used instead of []*DjangoMigration. +type DjangoMigrationSlice []*DjangoMigration + +// DjangoMigrations contains methods to work with the django_migrations table +var DjangoMigrations = mysql.NewTablex[*DjangoMigration, DjangoMigrationSlice, *DjangoMigrationSetter]("django_migrations", buildDjangoMigrationColumns("django_migrations"), []string{"id"}) + +// DjangoMigrationsQuery is a query on the django_migrations table +type DjangoMigrationsQuery = *mysql.ViewQuery[*DjangoMigration, DjangoMigrationSlice] + +func buildDjangoMigrationColumns(alias string) djangoMigrationColumns { + return djangoMigrationColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "app", "name", "applied", + ).WithParent("django_migrations"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + App: mysql.Quote(alias, "app"), + Name: mysql.Quote(alias, "name"), + Applied: mysql.Quote(alias, "applied"), + } +} + +type djangoMigrationColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + App mysql.Expression + Name mysql.Expression + Applied mysql.Expression +} + +func (c djangoMigrationColumns) Alias() string { + return c.tableAlias +} + +func (djangoMigrationColumns) AliasedAs(alias string) djangoMigrationColumns { + return buildDjangoMigrationColumns(alias) +} + +// DjangoMigrationSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type DjangoMigrationSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + App omit.Val[string] `db:"app" ` + Name omit.Val[string] `db:"name" ` + Applied omit.Val[time.Time] `db:"applied" ` +} + +func (s DjangoMigrationSetter) SetColumns() []string { + vals := make([]string, 0, 4) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.App.IsValue() { + vals = append(vals, "app") + } + if s.Name.IsValue() { + vals = append(vals, "name") + } + if s.Applied.IsValue() { + vals = append(vals, "applied") + } + return vals +} + +func (s DjangoMigrationSetter) Overwrite(t *DjangoMigration) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.App.IsValue() { + t.App = s.App.MustGet() + } + if s.Name.IsValue() { + t.Name = s.Name.MustGet() + } + if s.Applied.IsValue() { + t.Applied = s.Applied.MustGet() + } +} + +func (s *DjangoMigrationSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoMigrations.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.App.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.App.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Name.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Name.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Applied.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Applied.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s DjangoMigrationSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("django_migrations")...) +} + +func (s DjangoMigrationSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 4) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.App.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "app")...), + mysql.Arg(s.App), + }}) + } + + if s.Name.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "name")...), + mysql.Arg(s.Name), + }}) + } + + if s.Applied.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "applied")...), + mysql.Arg(s.Applied), + }}) + } + + return exprs +} + +// FindDjangoMigration retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindDjangoMigration(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*DjangoMigration, error) { + if len(cols) == 0 { + return DjangoMigrations.Query( + sm.Where(DjangoMigrations.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return DjangoMigrations.Query( + sm.Where(DjangoMigrations.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(DjangoMigrations.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// DjangoMigrationExists checks the presence of a single record by primary key +func DjangoMigrationExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return DjangoMigrations.Query( + sm.Where(DjangoMigrations.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after DjangoMigration is retrieved from the database +func (o *DjangoMigration) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoMigrations.AfterSelectHooks.RunHooks(ctx, exec, DjangoMigrationSlice{o}) + case bob.QueryTypeInsert: + ctx, err = DjangoMigrations.AfterInsertHooks.RunHooks(ctx, exec, DjangoMigrationSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = DjangoMigrations.AfterUpdateHooks.RunHooks(ctx, exec, DjangoMigrationSlice{o}) + case bob.QueryTypeDelete: + ctx, err = DjangoMigrations.AfterDeleteHooks.RunHooks(ctx, exec, DjangoMigrationSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the DjangoMigration +func (o *DjangoMigration) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *DjangoMigration) pkEQ() dialect.Expression { + return mysql.Quote("django_migrations", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the DjangoMigration +func (o *DjangoMigration) Update(ctx context.Context, exec bob.Executor, s *DjangoMigrationSetter) error { + _, err := DjangoMigrations.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single DjangoMigration record with an executor +func (o *DjangoMigration) Delete(ctx context.Context, exec bob.Executor) error { + _, err := DjangoMigrations.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the DjangoMigration using the executor +func (o *DjangoMigration) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := DjangoMigrations.Query( + sm.Where(DjangoMigrations.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + + *o = *o2 + + return nil +} + +// AfterQueryHook is called after DjangoMigrationSlice is retrieved from the database +func (o DjangoMigrationSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoMigrations.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = DjangoMigrations.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = DjangoMigrations.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = DjangoMigrations.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o DjangoMigrationSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("django_migrations", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o DjangoMigrationSlice) copyMatchingRows(from ...*DjangoMigration) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o DjangoMigrationSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoMigrations.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoMigration: + o.copyMatchingRows(retrieved) + case []*DjangoMigration: + o.copyMatchingRows(retrieved...) + case DjangoMigrationSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoMigration or a slice of DjangoMigration + // then run the AfterUpdateHooks on the slice + _, err = DjangoMigrations.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o DjangoMigrationSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoMigrations.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoMigration: + o.copyMatchingRows(retrieved) + case []*DjangoMigration: + o.copyMatchingRows(retrieved...) + case DjangoMigrationSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoMigration or a slice of DjangoMigration + // then run the AfterDeleteHooks on the slice + _, err = DjangoMigrations.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o DjangoMigrationSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals DjangoMigrationSetter) error { + _, err := DjangoMigrations.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o DjangoMigrationSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := DjangoMigrations.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o DjangoMigrationSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := DjangoMigrations.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +type djangoMigrationWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + App mysql.WhereMod[Q, string] + Name mysql.WhereMod[Q, string] + Applied mysql.WhereMod[Q, time.Time] +} + +func (djangoMigrationWhere[Q]) AliasedAs(alias string) djangoMigrationWhere[Q] { + return buildDjangoMigrationWhere[Q](buildDjangoMigrationColumns(alias)) +} + +func buildDjangoMigrationWhere[Q mysql.Filterable](cols djangoMigrationColumns) djangoMigrationWhere[Q] { + return djangoMigrationWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + App: mysql.Where[Q, string](cols.App), + Name: mysql.Where[Q, string](cols.Name), + Applied: mysql.Where[Q, time.Time](cols.Applied), + } +} diff --git a/database/mcp/models/django_session.bob.go b/database/mcp/models/django_session.bob.go new file mode 100644 index 0000000..12c4cd0 --- /dev/null +++ b/database/mcp/models/django_session.bob.go @@ -0,0 +1,395 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "io" + "time" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" +) + +// DjangoSession is an object representing the database table. +type DjangoSession struct { + SessionKey string `db:"session_key,pk" ` + SessionData string `db:"session_data" ` + ExpireDate time.Time `db:"expire_date" ` +} + +// DjangoSessionSlice is an alias for a slice of pointers to DjangoSession. +// This should almost always be used instead of []*DjangoSession. +type DjangoSessionSlice []*DjangoSession + +// DjangoSessions contains methods to work with the django_session table +var DjangoSessions = mysql.NewTablex[*DjangoSession, DjangoSessionSlice, *DjangoSessionSetter]("django_session", buildDjangoSessionColumns("django_session"), []string{"session_key"}) + +// DjangoSessionsQuery is a query on the django_session table +type DjangoSessionsQuery = *mysql.ViewQuery[*DjangoSession, DjangoSessionSlice] + +func buildDjangoSessionColumns(alias string) djangoSessionColumns { + return djangoSessionColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "session_key", "session_data", "expire_date", + ).WithParent("django_session"), + tableAlias: alias, + SessionKey: mysql.Quote(alias, "session_key"), + SessionData: mysql.Quote(alias, "session_data"), + ExpireDate: mysql.Quote(alias, "expire_date"), + } +} + +type djangoSessionColumns struct { + expr.ColumnsExpr + tableAlias string + SessionKey mysql.Expression + SessionData mysql.Expression + ExpireDate mysql.Expression +} + +func (c djangoSessionColumns) Alias() string { + return c.tableAlias +} + +func (djangoSessionColumns) AliasedAs(alias string) djangoSessionColumns { + return buildDjangoSessionColumns(alias) +} + +// DjangoSessionSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type DjangoSessionSetter struct { + SessionKey omit.Val[string] `db:"session_key,pk" ` + SessionData omit.Val[string] `db:"session_data" ` + ExpireDate omit.Val[time.Time] `db:"expire_date" ` +} + +func (s DjangoSessionSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.SessionKey.IsValue() { + vals = append(vals, "session_key") + } + if s.SessionData.IsValue() { + vals = append(vals, "session_data") + } + if s.ExpireDate.IsValue() { + vals = append(vals, "expire_date") + } + return vals +} + +func (s DjangoSessionSetter) Overwrite(t *DjangoSession) { + if s.SessionKey.IsValue() { + t.SessionKey = s.SessionKey.MustGet() + } + if s.SessionData.IsValue() { + t.SessionData = s.SessionData.MustGet() + } + if s.ExpireDate.IsValue() { + t.ExpireDate = s.ExpireDate.MustGet() + } +} + +func (s *DjangoSessionSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoSessions.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SessionKey.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SessionKey.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SessionData.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SessionData.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ExpireDate.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ExpireDate.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s DjangoSessionSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("django_session")...) +} + +func (s DjangoSessionSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.SessionKey.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "session_key")...), + mysql.Arg(s.SessionKey), + }}) + } + + if s.SessionData.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "session_data")...), + mysql.Arg(s.SessionData), + }}) + } + + if s.ExpireDate.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "expire_date")...), + mysql.Arg(s.ExpireDate), + }}) + } + + return exprs +} + +// FindDjangoSession retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindDjangoSession(ctx context.Context, exec bob.Executor, SessionKeyPK string, cols ...string) (*DjangoSession, error) { + if len(cols) == 0 { + return DjangoSessions.Query( + sm.Where(DjangoSessions.Columns.SessionKey.EQ(mysql.Arg(SessionKeyPK))), + ).One(ctx, exec) + } + + return DjangoSessions.Query( + sm.Where(DjangoSessions.Columns.SessionKey.EQ(mysql.Arg(SessionKeyPK))), + sm.Columns(DjangoSessions.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// DjangoSessionExists checks the presence of a single record by primary key +func DjangoSessionExists(ctx context.Context, exec bob.Executor, SessionKeyPK string) (bool, error) { + return DjangoSessions.Query( + sm.Where(DjangoSessions.Columns.SessionKey.EQ(mysql.Arg(SessionKeyPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after DjangoSession is retrieved from the database +func (o *DjangoSession) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoSessions.AfterSelectHooks.RunHooks(ctx, exec, DjangoSessionSlice{o}) + case bob.QueryTypeInsert: + ctx, err = DjangoSessions.AfterInsertHooks.RunHooks(ctx, exec, DjangoSessionSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = DjangoSessions.AfterUpdateHooks.RunHooks(ctx, exec, DjangoSessionSlice{o}) + case bob.QueryTypeDelete: + ctx, err = DjangoSessions.AfterDeleteHooks.RunHooks(ctx, exec, DjangoSessionSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the DjangoSession +func (o *DjangoSession) primaryKeyVals() bob.Expression { + return mysql.Arg(o.SessionKey) +} + +func (o *DjangoSession) pkEQ() dialect.Expression { + return mysql.Quote("django_session", "session_key").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the DjangoSession +func (o *DjangoSession) Update(ctx context.Context, exec bob.Executor, s *DjangoSessionSetter) error { + _, err := DjangoSessions.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single DjangoSession record with an executor +func (o *DjangoSession) Delete(ctx context.Context, exec bob.Executor) error { + _, err := DjangoSessions.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the DjangoSession using the executor +func (o *DjangoSession) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := DjangoSessions.Query( + sm.Where(DjangoSessions.Columns.SessionKey.EQ(mysql.Arg(o.SessionKey))), + ).One(ctx, exec) + if err != nil { + return err + } + + *o = *o2 + + return nil +} + +// AfterQueryHook is called after DjangoSessionSlice is retrieved from the database +func (o DjangoSessionSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoSessions.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = DjangoSessions.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = DjangoSessions.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = DjangoSessions.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o DjangoSessionSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("django_session", "session_key").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o DjangoSessionSlice) copyMatchingRows(from ...*DjangoSession) { + for i, old := range o { + for _, new := range from { + if new.SessionKey != old.SessionKey { + continue + } + + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o DjangoSessionSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoSessions.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoSession: + o.copyMatchingRows(retrieved) + case []*DjangoSession: + o.copyMatchingRows(retrieved...) + case DjangoSessionSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoSession or a slice of DjangoSession + // then run the AfterUpdateHooks on the slice + _, err = DjangoSessions.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o DjangoSessionSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoSessions.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoSession: + o.copyMatchingRows(retrieved) + case []*DjangoSession: + o.copyMatchingRows(retrieved...) + case DjangoSessionSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoSession or a slice of DjangoSession + // then run the AfterDeleteHooks on the slice + _, err = DjangoSessions.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o DjangoSessionSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals DjangoSessionSetter) error { + _, err := DjangoSessions.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o DjangoSessionSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := DjangoSessions.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o DjangoSessionSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := DjangoSessions.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +type djangoSessionWhere[Q mysql.Filterable] struct { + SessionKey mysql.WhereMod[Q, string] + SessionData mysql.WhereMod[Q, string] + ExpireDate mysql.WhereMod[Q, time.Time] +} + +func (djangoSessionWhere[Q]) AliasedAs(alias string) djangoSessionWhere[Q] { + return buildDjangoSessionWhere[Q](buildDjangoSessionColumns(alias)) +} + +func buildDjangoSessionWhere[Q mysql.Filterable](cols djangoSessionColumns) djangoSessionWhere[Q] { + return djangoSessionWhere[Q]{ + SessionKey: mysql.Where[Q, string](cols.SessionKey), + SessionData: mysql.Where[Q, string](cols.SessionData), + ExpireDate: mysql.Where[Q, time.Time](cols.ExpireDate), + } +} diff --git a/database/mcp/models/django_site.bob.go b/database/mcp/models/django_site.bob.go new file mode 100644 index 0000000..59cb0d2 --- /dev/null +++ b/database/mcp/models/django_site.bob.go @@ -0,0 +1,394 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" +) + +// DjangoSite is an object representing the database table. +type DjangoSite struct { + ID int32 `db:"id,pk,autoincr" ` + Domain string `db:"domain" ` + Name string `db:"name" ` +} + +// DjangoSiteSlice is an alias for a slice of pointers to DjangoSite. +// This should almost always be used instead of []*DjangoSite. +type DjangoSiteSlice []*DjangoSite + +// DjangoSites contains methods to work with the django_site table +var DjangoSites = mysql.NewTablex[*DjangoSite, DjangoSiteSlice, *DjangoSiteSetter]("django_site", buildDjangoSiteColumns("django_site"), []string{"id"}, []string{"domain"}) + +// DjangoSitesQuery is a query on the django_site table +type DjangoSitesQuery = *mysql.ViewQuery[*DjangoSite, DjangoSiteSlice] + +func buildDjangoSiteColumns(alias string) djangoSiteColumns { + return djangoSiteColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "domain", "name", + ).WithParent("django_site"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Domain: mysql.Quote(alias, "domain"), + Name: mysql.Quote(alias, "name"), + } +} + +type djangoSiteColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Domain mysql.Expression + Name mysql.Expression +} + +func (c djangoSiteColumns) Alias() string { + return c.tableAlias +} + +func (djangoSiteColumns) AliasedAs(alias string) djangoSiteColumns { + return buildDjangoSiteColumns(alias) +} + +// DjangoSiteSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type DjangoSiteSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Domain omit.Val[string] `db:"domain" ` + Name omit.Val[string] `db:"name" ` +} + +func (s DjangoSiteSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Domain.IsValue() { + vals = append(vals, "domain") + } + if s.Name.IsValue() { + vals = append(vals, "name") + } + return vals +} + +func (s DjangoSiteSetter) Overwrite(t *DjangoSite) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Domain.IsValue() { + t.Domain = s.Domain.MustGet() + } + if s.Name.IsValue() { + t.Name = s.Name.MustGet() + } +} + +func (s *DjangoSiteSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoSites.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Domain.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Domain.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Name.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Name.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s DjangoSiteSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("django_site")...) +} + +func (s DjangoSiteSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Domain.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "domain")...), + mysql.Arg(s.Domain), + }}) + } + + if s.Name.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "name")...), + mysql.Arg(s.Name), + }}) + } + + return exprs +} + +// FindDjangoSite retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindDjangoSite(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*DjangoSite, error) { + if len(cols) == 0 { + return DjangoSites.Query( + sm.Where(DjangoSites.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return DjangoSites.Query( + sm.Where(DjangoSites.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(DjangoSites.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// DjangoSiteExists checks the presence of a single record by primary key +func DjangoSiteExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return DjangoSites.Query( + sm.Where(DjangoSites.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after DjangoSite is retrieved from the database +func (o *DjangoSite) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoSites.AfterSelectHooks.RunHooks(ctx, exec, DjangoSiteSlice{o}) + case bob.QueryTypeInsert: + ctx, err = DjangoSites.AfterInsertHooks.RunHooks(ctx, exec, DjangoSiteSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = DjangoSites.AfterUpdateHooks.RunHooks(ctx, exec, DjangoSiteSlice{o}) + case bob.QueryTypeDelete: + ctx, err = DjangoSites.AfterDeleteHooks.RunHooks(ctx, exec, DjangoSiteSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the DjangoSite +func (o *DjangoSite) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *DjangoSite) pkEQ() dialect.Expression { + return mysql.Quote("django_site", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the DjangoSite +func (o *DjangoSite) Update(ctx context.Context, exec bob.Executor, s *DjangoSiteSetter) error { + _, err := DjangoSites.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single DjangoSite record with an executor +func (o *DjangoSite) Delete(ctx context.Context, exec bob.Executor) error { + _, err := DjangoSites.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the DjangoSite using the executor +func (o *DjangoSite) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := DjangoSites.Query( + sm.Where(DjangoSites.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + + *o = *o2 + + return nil +} + +// AfterQueryHook is called after DjangoSiteSlice is retrieved from the database +func (o DjangoSiteSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoSites.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = DjangoSites.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = DjangoSites.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = DjangoSites.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o DjangoSiteSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("django_site", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o DjangoSiteSlice) copyMatchingRows(from ...*DjangoSite) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o DjangoSiteSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoSites.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoSite: + o.copyMatchingRows(retrieved) + case []*DjangoSite: + o.copyMatchingRows(retrieved...) + case DjangoSiteSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoSite or a slice of DjangoSite + // then run the AfterUpdateHooks on the slice + _, err = DjangoSites.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o DjangoSiteSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoSites.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoSite: + o.copyMatchingRows(retrieved) + case []*DjangoSite: + o.copyMatchingRows(retrieved...) + case DjangoSiteSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoSite or a slice of DjangoSite + // then run the AfterDeleteHooks on the slice + _, err = DjangoSites.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o DjangoSiteSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals DjangoSiteSetter) error { + _, err := DjangoSites.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o DjangoSiteSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := DjangoSites.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o DjangoSiteSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := DjangoSites.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +type djangoSiteWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Domain mysql.WhereMod[Q, string] + Name mysql.WhereMod[Q, string] +} + +func (djangoSiteWhere[Q]) AliasedAs(alias string) djangoSiteWhere[Q] { + return buildDjangoSiteWhere[Q](buildDjangoSiteColumns(alias)) +} + +func buildDjangoSiteWhere[Q mysql.Filterable](cols djangoSiteColumns) djangoSiteWhere[Q] { + return djangoSiteWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Domain: mysql.Where[Q, string](cols.Domain), + Name: mysql.Where[Q, string](cols.Name), + } +} diff --git a/database/mcp/models/locations_archipelago.bob.go b/database/mcp/models/locations_archipelago.bob.go new file mode 100644 index 0000000..fdc5f0a --- /dev/null +++ b/database/mcp/models/locations_archipelago.bob.go @@ -0,0 +1,664 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsArchipelago is an object representing the database table. +type LocationsArchipelago struct { + ID int32 `db:"id,pk,autoincr" ` + ArchipelagoURL string `db:"archipelago_url" ` + ArchipelagoUser string `db:"archipelago_user" ` + ArchipelagoPassword string `db:"archipelago_password" ` + SpaceID string `db:"space_id" ` + + R locationsArchipelagoR `db:"-" ` +} + +// LocationsArchipelagoSlice is an alias for a slice of pointers to LocationsArchipelago. +// This should almost always be used instead of []*LocationsArchipelago. +type LocationsArchipelagoSlice []*LocationsArchipelago + +// LocationsArchipelagos contains methods to work with the locations_archipelago table +var LocationsArchipelagos = mysql.NewTablex[*LocationsArchipelago, LocationsArchipelagoSlice, *LocationsArchipelagoSetter]("locations_archipelago", buildLocationsArchipelagoColumns("locations_archipelago"), []string{"id"}, []string{"space_id"}) + +// LocationsArchipelagosQuery is a query on the locations_archipelago table +type LocationsArchipelagosQuery = *mysql.ViewQuery[*LocationsArchipelago, LocationsArchipelagoSlice] + +// locationsArchipelagoR is where relationships are stored. +type locationsArchipelagoR struct { + SpaceLocationsSpace *LocationsSpace // locations_archipelago_space_id_be47fd5c_fk_locations_space_uuid +} + +func buildLocationsArchipelagoColumns(alias string) locationsArchipelagoColumns { + return locationsArchipelagoColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "archipelago_url", "archipelago_user", "archipelago_password", "space_id", + ).WithParent("locations_archipelago"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + ArchipelagoURL: mysql.Quote(alias, "archipelago_url"), + ArchipelagoUser: mysql.Quote(alias, "archipelago_user"), + ArchipelagoPassword: mysql.Quote(alias, "archipelago_password"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsArchipelagoColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + ArchipelagoURL mysql.Expression + ArchipelagoUser mysql.Expression + ArchipelagoPassword mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsArchipelagoColumns) Alias() string { + return c.tableAlias +} + +func (locationsArchipelagoColumns) AliasedAs(alias string) locationsArchipelagoColumns { + return buildLocationsArchipelagoColumns(alias) +} + +// LocationsArchipelagoSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsArchipelagoSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + ArchipelagoURL omit.Val[string] `db:"archipelago_url" ` + ArchipelagoUser omit.Val[string] `db:"archipelago_user" ` + ArchipelagoPassword omit.Val[string] `db:"archipelago_password" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsArchipelagoSetter) SetColumns() []string { + vals := make([]string, 0, 5) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.ArchipelagoURL.IsValue() { + vals = append(vals, "archipelago_url") + } + if s.ArchipelagoUser.IsValue() { + vals = append(vals, "archipelago_user") + } + if s.ArchipelagoPassword.IsValue() { + vals = append(vals, "archipelago_password") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsArchipelagoSetter) Overwrite(t *LocationsArchipelago) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.ArchipelagoURL.IsValue() { + t.ArchipelagoURL = s.ArchipelagoURL.MustGet() + } + if s.ArchipelagoUser.IsValue() { + t.ArchipelagoUser = s.ArchipelagoUser.MustGet() + } + if s.ArchipelagoPassword.IsValue() { + t.ArchipelagoPassword = s.ArchipelagoPassword.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsArchipelagoSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsArchipelagos.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ArchipelagoURL.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ArchipelagoURL.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ArchipelagoUser.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ArchipelagoUser.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ArchipelagoPassword.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ArchipelagoPassword.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsArchipelagoSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_archipelago")...) +} + +func (s LocationsArchipelagoSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 5) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.ArchipelagoURL.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "archipelago_url")...), + mysql.Arg(s.ArchipelagoURL), + }}) + } + + if s.ArchipelagoUser.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "archipelago_user")...), + mysql.Arg(s.ArchipelagoUser), + }}) + } + + if s.ArchipelagoPassword.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "archipelago_password")...), + mysql.Arg(s.ArchipelagoPassword), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsArchipelago retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsArchipelago(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsArchipelago, error) { + if len(cols) == 0 { + return LocationsArchipelagos.Query( + sm.Where(LocationsArchipelagos.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsArchipelagos.Query( + sm.Where(LocationsArchipelagos.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsArchipelagos.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsArchipelagoExists checks the presence of a single record by primary key +func LocationsArchipelagoExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsArchipelagos.Query( + sm.Where(LocationsArchipelagos.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsArchipelago is retrieved from the database +func (o *LocationsArchipelago) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsArchipelagos.AfterSelectHooks.RunHooks(ctx, exec, LocationsArchipelagoSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsArchipelagos.AfterInsertHooks.RunHooks(ctx, exec, LocationsArchipelagoSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsArchipelagos.AfterUpdateHooks.RunHooks(ctx, exec, LocationsArchipelagoSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsArchipelagos.AfterDeleteHooks.RunHooks(ctx, exec, LocationsArchipelagoSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsArchipelago +func (o *LocationsArchipelago) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsArchipelago) pkEQ() dialect.Expression { + return mysql.Quote("locations_archipelago", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsArchipelago +func (o *LocationsArchipelago) Update(ctx context.Context, exec bob.Executor, s *LocationsArchipelagoSetter) error { + _, err := LocationsArchipelagos.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsArchipelago record with an executor +func (o *LocationsArchipelago) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsArchipelagos.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsArchipelago using the executor +func (o *LocationsArchipelago) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsArchipelagos.Query( + sm.Where(LocationsArchipelagos.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsArchipelagoSlice is retrieved from the database +func (o LocationsArchipelagoSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsArchipelagos.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsArchipelagos.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsArchipelagos.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsArchipelagos.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsArchipelagoSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_archipelago", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsArchipelagoSlice) copyMatchingRows(from ...*LocationsArchipelago) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsArchipelagoSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsArchipelagos.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsArchipelago: + o.copyMatchingRows(retrieved) + case []*LocationsArchipelago: + o.copyMatchingRows(retrieved...) + case LocationsArchipelagoSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsArchipelago or a slice of LocationsArchipelago + // then run the AfterUpdateHooks on the slice + _, err = LocationsArchipelagos.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsArchipelagoSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsArchipelagos.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsArchipelago: + o.copyMatchingRows(retrieved) + case []*LocationsArchipelago: + o.copyMatchingRows(retrieved...) + case LocationsArchipelagoSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsArchipelago or a slice of LocationsArchipelago + // then run the AfterDeleteHooks on the slice + _, err = LocationsArchipelagos.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsArchipelagoSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsArchipelagoSetter) error { + _, err := LocationsArchipelagos.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsArchipelagoSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsArchipelagos.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsArchipelagoSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsArchipelagos.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsArchipelago) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsArchipelagoSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsArchipelagoSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsArchipelago0 *LocationsArchipelago, locationsSpace1 *LocationsSpace) (*LocationsArchipelago, error) { + setter := &LocationsArchipelagoSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsArchipelago0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsArchipelagoSpaceLocationsSpace0: %w", err) + } + + return locationsArchipelago0, nil +} + +func (locationsArchipelago0 *LocationsArchipelago) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsArchipelagoSpaceLocationsSpace0(ctx, exec, 1, locationsArchipelago0, locationsSpace1) + if err != nil { + return err + } + + locationsArchipelago0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsArchipelago = locationsArchipelago0 + + return nil +} + +func (locationsArchipelago0 *LocationsArchipelago) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsArchipelagoSpaceLocationsSpace0(ctx, exec, 1, locationsArchipelago0, locationsSpace1) + if err != nil { + return err + } + + locationsArchipelago0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsArchipelago = locationsArchipelago0 + + return nil +} + +type locationsArchipelagoWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + ArchipelagoURL mysql.WhereMod[Q, string] + ArchipelagoUser mysql.WhereMod[Q, string] + ArchipelagoPassword mysql.WhereMod[Q, string] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsArchipelagoWhere[Q]) AliasedAs(alias string) locationsArchipelagoWhere[Q] { + return buildLocationsArchipelagoWhere[Q](buildLocationsArchipelagoColumns(alias)) +} + +func buildLocationsArchipelagoWhere[Q mysql.Filterable](cols locationsArchipelagoColumns) locationsArchipelagoWhere[Q] { + return locationsArchipelagoWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + ArchipelagoURL: mysql.Where[Q, string](cols.ArchipelagoURL), + ArchipelagoUser: mysql.Where[Q, string](cols.ArchipelagoUser), + ArchipelagoPassword: mysql.Where[Q, string](cols.ArchipelagoPassword), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsArchipelago) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsArchipelago cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsArchipelago = o + } + return nil + default: + return fmt.Errorf("locationsArchipelago has no relationship %q", name) + } +} + +type locationsArchipelagoPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsArchipelagoPreloader() locationsArchipelagoPreloader { + return locationsArchipelagoPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsArchipelagos, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsArchipelagoThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsArchipelagoThenLoader[Q orm.Loadable]() locationsArchipelagoThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsArchipelagoThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsArchipelago's SpaceLocationsSpace into the .R struct +func (o *LocationsArchipelago) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsArchipelago = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsArchipelago's SpaceLocationsSpace into the .R struct +func (os LocationsArchipelagoSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsArchipelago = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsArchipelagoJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsArchipelagoJoins[Q]) aliasedAs(alias string) locationsArchipelagoJoins[Q] { + return buildLocationsArchipelagoJoins[Q](buildLocationsArchipelagoColumns(alias), j.typ) +} + +func buildLocationsArchipelagoJoins[Q dialect.Joinable](cols locationsArchipelagoColumns, typ string) locationsArchipelagoJoins[Q] { + return locationsArchipelagoJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_arkivum.bob.go b/database/mcp/models/locations_arkivum.bob.go new file mode 100644 index 0000000..452b0cd --- /dev/null +++ b/database/mcp/models/locations_arkivum.bob.go @@ -0,0 +1,666 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsArkivum is an object representing the database table. +type LocationsArkivum struct { + ID int32 `db:"id,pk,autoincr" ` + Host string `db:"host" ` + RemoteUser null.Val[string] `db:"remote_user" ` + RemoteName null.Val[string] `db:"remote_name" ` + SpaceID string `db:"space_id" ` + + R locationsArkivumR `db:"-" ` +} + +// LocationsArkivumSlice is an alias for a slice of pointers to LocationsArkivum. +// This should almost always be used instead of []*LocationsArkivum. +type LocationsArkivumSlice []*LocationsArkivum + +// LocationsArkivums contains methods to work with the locations_arkivum table +var LocationsArkivums = mysql.NewTablex[*LocationsArkivum, LocationsArkivumSlice, *LocationsArkivumSetter]("locations_arkivum", buildLocationsArkivumColumns("locations_arkivum"), []string{"id"}, []string{"space_id"}) + +// LocationsArkivumsQuery is a query on the locations_arkivum table +type LocationsArkivumsQuery = *mysql.ViewQuery[*LocationsArkivum, LocationsArkivumSlice] + +// locationsArkivumR is where relationships are stored. +type locationsArkivumR struct { + SpaceLocationsSpace *LocationsSpace // locations_arkivum_space_id_d159e309_fk_locations_space_uuid +} + +func buildLocationsArkivumColumns(alias string) locationsArkivumColumns { + return locationsArkivumColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "host", "remote_user", "remote_name", "space_id", + ).WithParent("locations_arkivum"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Host: mysql.Quote(alias, "host"), + RemoteUser: mysql.Quote(alias, "remote_user"), + RemoteName: mysql.Quote(alias, "remote_name"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsArkivumColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Host mysql.Expression + RemoteUser mysql.Expression + RemoteName mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsArkivumColumns) Alias() string { + return c.tableAlias +} + +func (locationsArkivumColumns) AliasedAs(alias string) locationsArkivumColumns { + return buildLocationsArkivumColumns(alias) +} + +// LocationsArkivumSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsArkivumSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Host omit.Val[string] `db:"host" ` + RemoteUser omitnull.Val[string] `db:"remote_user" ` + RemoteName omitnull.Val[string] `db:"remote_name" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsArkivumSetter) SetColumns() []string { + vals := make([]string, 0, 5) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Host.IsValue() { + vals = append(vals, "host") + } + if !s.RemoteUser.IsUnset() { + vals = append(vals, "remote_user") + } + if !s.RemoteName.IsUnset() { + vals = append(vals, "remote_name") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsArkivumSetter) Overwrite(t *LocationsArkivum) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Host.IsValue() { + t.Host = s.Host.MustGet() + } + if !s.RemoteUser.IsUnset() { + t.RemoteUser = s.RemoteUser.MustGetNull() + } + if !s.RemoteName.IsUnset() { + t.RemoteName = s.RemoteName.MustGetNull() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsArkivumSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsArkivums.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Host.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Host.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.RemoteUser.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RemoteUser.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.RemoteName.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RemoteName.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsArkivumSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_arkivum")...) +} + +func (s LocationsArkivumSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 5) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Host.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "host")...), + mysql.Arg(s.Host), + }}) + } + + if !s.RemoteUser.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "remote_user")...), + mysql.Arg(s.RemoteUser), + }}) + } + + if !s.RemoteName.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "remote_name")...), + mysql.Arg(s.RemoteName), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsArkivum retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsArkivum(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsArkivum, error) { + if len(cols) == 0 { + return LocationsArkivums.Query( + sm.Where(LocationsArkivums.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsArkivums.Query( + sm.Where(LocationsArkivums.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsArkivums.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsArkivumExists checks the presence of a single record by primary key +func LocationsArkivumExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsArkivums.Query( + sm.Where(LocationsArkivums.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsArkivum is retrieved from the database +func (o *LocationsArkivum) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsArkivums.AfterSelectHooks.RunHooks(ctx, exec, LocationsArkivumSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsArkivums.AfterInsertHooks.RunHooks(ctx, exec, LocationsArkivumSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsArkivums.AfterUpdateHooks.RunHooks(ctx, exec, LocationsArkivumSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsArkivums.AfterDeleteHooks.RunHooks(ctx, exec, LocationsArkivumSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsArkivum +func (o *LocationsArkivum) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsArkivum) pkEQ() dialect.Expression { + return mysql.Quote("locations_arkivum", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsArkivum +func (o *LocationsArkivum) Update(ctx context.Context, exec bob.Executor, s *LocationsArkivumSetter) error { + _, err := LocationsArkivums.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsArkivum record with an executor +func (o *LocationsArkivum) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsArkivums.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsArkivum using the executor +func (o *LocationsArkivum) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsArkivums.Query( + sm.Where(LocationsArkivums.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsArkivumSlice is retrieved from the database +func (o LocationsArkivumSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsArkivums.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsArkivums.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsArkivums.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsArkivums.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsArkivumSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_arkivum", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsArkivumSlice) copyMatchingRows(from ...*LocationsArkivum) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsArkivumSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsArkivums.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsArkivum: + o.copyMatchingRows(retrieved) + case []*LocationsArkivum: + o.copyMatchingRows(retrieved...) + case LocationsArkivumSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsArkivum or a slice of LocationsArkivum + // then run the AfterUpdateHooks on the slice + _, err = LocationsArkivums.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsArkivumSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsArkivums.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsArkivum: + o.copyMatchingRows(retrieved) + case []*LocationsArkivum: + o.copyMatchingRows(retrieved...) + case LocationsArkivumSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsArkivum or a slice of LocationsArkivum + // then run the AfterDeleteHooks on the slice + _, err = LocationsArkivums.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsArkivumSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsArkivumSetter) error { + _, err := LocationsArkivums.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsArkivumSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsArkivums.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsArkivumSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsArkivums.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsArkivum) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsArkivumSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsArkivumSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsArkivum0 *LocationsArkivum, locationsSpace1 *LocationsSpace) (*LocationsArkivum, error) { + setter := &LocationsArkivumSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsArkivum0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsArkivumSpaceLocationsSpace0: %w", err) + } + + return locationsArkivum0, nil +} + +func (locationsArkivum0 *LocationsArkivum) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsArkivumSpaceLocationsSpace0(ctx, exec, 1, locationsArkivum0, locationsSpace1) + if err != nil { + return err + } + + locationsArkivum0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsArkivum = locationsArkivum0 + + return nil +} + +func (locationsArkivum0 *LocationsArkivum) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsArkivumSpaceLocationsSpace0(ctx, exec, 1, locationsArkivum0, locationsSpace1) + if err != nil { + return err + } + + locationsArkivum0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsArkivum = locationsArkivum0 + + return nil +} + +type locationsArkivumWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Host mysql.WhereMod[Q, string] + RemoteUser mysql.WhereNullMod[Q, string] + RemoteName mysql.WhereNullMod[Q, string] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsArkivumWhere[Q]) AliasedAs(alias string) locationsArkivumWhere[Q] { + return buildLocationsArkivumWhere[Q](buildLocationsArkivumColumns(alias)) +} + +func buildLocationsArkivumWhere[Q mysql.Filterable](cols locationsArkivumColumns) locationsArkivumWhere[Q] { + return locationsArkivumWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Host: mysql.Where[Q, string](cols.Host), + RemoteUser: mysql.WhereNull[Q, string](cols.RemoteUser), + RemoteName: mysql.WhereNull[Q, string](cols.RemoteName), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsArkivum) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsArkivum cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsArkivum = o + } + return nil + default: + return fmt.Errorf("locationsArkivum has no relationship %q", name) + } +} + +type locationsArkivumPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsArkivumPreloader() locationsArkivumPreloader { + return locationsArkivumPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsArkivums, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsArkivumThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsArkivumThenLoader[Q orm.Loadable]() locationsArkivumThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsArkivumThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsArkivum's SpaceLocationsSpace into the .R struct +func (o *LocationsArkivum) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsArkivum = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsArkivum's SpaceLocationsSpace into the .R struct +func (os LocationsArkivumSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsArkivum = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsArkivumJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsArkivumJoins[Q]) aliasedAs(alias string) locationsArkivumJoins[Q] { + return buildLocationsArkivumJoins[Q](buildLocationsArkivumColumns(alias), j.typ) +} + +func buildLocationsArkivumJoins[Q dialect.Joinable](cols locationsArkivumColumns, typ string) locationsArkivumJoins[Q] { + return locationsArkivumJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_async.bob.go b/database/mcp/models/locations_async.bob.go new file mode 100644 index 0000000..86805cb --- /dev/null +++ b/database/mcp/models/locations_async.bob.go @@ -0,0 +1,517 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "io" + "time" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" +) + +// LocationsAsync is an object representing the database table. +type LocationsAsync struct { + ID int32 `db:"id,pk,autoincr" ` + Completed bool `db:"completed" ` + WasError bool `db:"was_error" ` + Result null.Val[[]byte] `db:"result" ` + Error null.Val[[]byte] `db:"error" ` + CreatedTime time.Time `db:"created_time" ` + UpdatedTime time.Time `db:"updated_time" ` + CompletedTime null.Val[time.Time] `db:"completed_time" ` +} + +// LocationsAsyncSlice is an alias for a slice of pointers to LocationsAsync. +// This should almost always be used instead of []*LocationsAsync. +type LocationsAsyncSlice []*LocationsAsync + +// LocationsAsyncs contains methods to work with the locations_async table +var LocationsAsyncs = mysql.NewTablex[*LocationsAsync, LocationsAsyncSlice, *LocationsAsyncSetter]("locations_async", buildLocationsAsyncColumns("locations_async"), []string{"id"}) + +// LocationsAsyncsQuery is a query on the locations_async table +type LocationsAsyncsQuery = *mysql.ViewQuery[*LocationsAsync, LocationsAsyncSlice] + +func buildLocationsAsyncColumns(alias string) locationsAsyncColumns { + return locationsAsyncColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "completed", "was_error", "result", "error", "created_time", "updated_time", "completed_time", + ).WithParent("locations_async"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Completed: mysql.Quote(alias, "completed"), + WasError: mysql.Quote(alias, "was_error"), + Result: mysql.Quote(alias, "result"), + Error: mysql.Quote(alias, "error"), + CreatedTime: mysql.Quote(alias, "created_time"), + UpdatedTime: mysql.Quote(alias, "updated_time"), + CompletedTime: mysql.Quote(alias, "completed_time"), + } +} + +type locationsAsyncColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Completed mysql.Expression + WasError mysql.Expression + Result mysql.Expression + Error mysql.Expression + CreatedTime mysql.Expression + UpdatedTime mysql.Expression + CompletedTime mysql.Expression +} + +func (c locationsAsyncColumns) Alias() string { + return c.tableAlias +} + +func (locationsAsyncColumns) AliasedAs(alias string) locationsAsyncColumns { + return buildLocationsAsyncColumns(alias) +} + +// LocationsAsyncSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsAsyncSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Completed omit.Val[bool] `db:"completed" ` + WasError omit.Val[bool] `db:"was_error" ` + Result omitnull.Val[[]byte] `db:"result" ` + Error omitnull.Val[[]byte] `db:"error" ` + CreatedTime omit.Val[time.Time] `db:"created_time" ` + UpdatedTime omit.Val[time.Time] `db:"updated_time" ` + CompletedTime omitnull.Val[time.Time] `db:"completed_time" ` +} + +func (s LocationsAsyncSetter) SetColumns() []string { + vals := make([]string, 0, 8) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Completed.IsValue() { + vals = append(vals, "completed") + } + if s.WasError.IsValue() { + vals = append(vals, "was_error") + } + if !s.Result.IsUnset() { + vals = append(vals, "result") + } + if !s.Error.IsUnset() { + vals = append(vals, "error") + } + if s.CreatedTime.IsValue() { + vals = append(vals, "created_time") + } + if s.UpdatedTime.IsValue() { + vals = append(vals, "updated_time") + } + if !s.CompletedTime.IsUnset() { + vals = append(vals, "completed_time") + } + return vals +} + +func (s LocationsAsyncSetter) Overwrite(t *LocationsAsync) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Completed.IsValue() { + t.Completed = s.Completed.MustGet() + } + if s.WasError.IsValue() { + t.WasError = s.WasError.MustGet() + } + if !s.Result.IsUnset() { + t.Result = s.Result.MustGetNull() + } + if !s.Error.IsUnset() { + t.Error = s.Error.MustGetNull() + } + if s.CreatedTime.IsValue() { + t.CreatedTime = s.CreatedTime.MustGet() + } + if s.UpdatedTime.IsValue() { + t.UpdatedTime = s.UpdatedTime.MustGet() + } + if !s.CompletedTime.IsUnset() { + t.CompletedTime = s.CompletedTime.MustGetNull() + } +} + +func (s *LocationsAsyncSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsAsyncs.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Completed.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Completed.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.WasError.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.WasError.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Result.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Result.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Error.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Error.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.CreatedTime.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.CreatedTime.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UpdatedTime.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UpdatedTime.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.CompletedTime.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.CompletedTime.MustGetNull()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsAsyncSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_async")...) +} + +func (s LocationsAsyncSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 8) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Completed.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "completed")...), + mysql.Arg(s.Completed), + }}) + } + + if s.WasError.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "was_error")...), + mysql.Arg(s.WasError), + }}) + } + + if !s.Result.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "result")...), + mysql.Arg(s.Result), + }}) + } + + if !s.Error.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "error")...), + mysql.Arg(s.Error), + }}) + } + + if s.CreatedTime.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "created_time")...), + mysql.Arg(s.CreatedTime), + }}) + } + + if s.UpdatedTime.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "updated_time")...), + mysql.Arg(s.UpdatedTime), + }}) + } + + if !s.CompletedTime.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "completed_time")...), + mysql.Arg(s.CompletedTime), + }}) + } + + return exprs +} + +// FindLocationsAsync retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsAsync(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsAsync, error) { + if len(cols) == 0 { + return LocationsAsyncs.Query( + sm.Where(LocationsAsyncs.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsAsyncs.Query( + sm.Where(LocationsAsyncs.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsAsyncs.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsAsyncExists checks the presence of a single record by primary key +func LocationsAsyncExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsAsyncs.Query( + sm.Where(LocationsAsyncs.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsAsync is retrieved from the database +func (o *LocationsAsync) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsAsyncs.AfterSelectHooks.RunHooks(ctx, exec, LocationsAsyncSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsAsyncs.AfterInsertHooks.RunHooks(ctx, exec, LocationsAsyncSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsAsyncs.AfterUpdateHooks.RunHooks(ctx, exec, LocationsAsyncSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsAsyncs.AfterDeleteHooks.RunHooks(ctx, exec, LocationsAsyncSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsAsync +func (o *LocationsAsync) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsAsync) pkEQ() dialect.Expression { + return mysql.Quote("locations_async", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsAsync +func (o *LocationsAsync) Update(ctx context.Context, exec bob.Executor, s *LocationsAsyncSetter) error { + _, err := LocationsAsyncs.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsAsync record with an executor +func (o *LocationsAsync) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsAsyncs.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsAsync using the executor +func (o *LocationsAsync) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsAsyncs.Query( + sm.Where(LocationsAsyncs.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsAsyncSlice is retrieved from the database +func (o LocationsAsyncSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsAsyncs.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsAsyncs.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsAsyncs.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsAsyncs.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsAsyncSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_async", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsAsyncSlice) copyMatchingRows(from ...*LocationsAsync) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsAsyncSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsAsyncs.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsAsync: + o.copyMatchingRows(retrieved) + case []*LocationsAsync: + o.copyMatchingRows(retrieved...) + case LocationsAsyncSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsAsync or a slice of LocationsAsync + // then run the AfterUpdateHooks on the slice + _, err = LocationsAsyncs.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsAsyncSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsAsyncs.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsAsync: + o.copyMatchingRows(retrieved) + case []*LocationsAsync: + o.copyMatchingRows(retrieved...) + case LocationsAsyncSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsAsync or a slice of LocationsAsync + // then run the AfterDeleteHooks on the slice + _, err = LocationsAsyncs.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsAsyncSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsAsyncSetter) error { + _, err := LocationsAsyncs.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsAsyncSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsAsyncs.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsAsyncSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsAsyncs.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +type locationsAsyncWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Completed mysql.WhereMod[Q, bool] + WasError mysql.WhereMod[Q, bool] + Result mysql.WhereNullMod[Q, []byte] + Error mysql.WhereNullMod[Q, []byte] + CreatedTime mysql.WhereMod[Q, time.Time] + UpdatedTime mysql.WhereMod[Q, time.Time] + CompletedTime mysql.WhereNullMod[Q, time.Time] +} + +func (locationsAsyncWhere[Q]) AliasedAs(alias string) locationsAsyncWhere[Q] { + return buildLocationsAsyncWhere[Q](buildLocationsAsyncColumns(alias)) +} + +func buildLocationsAsyncWhere[Q mysql.Filterable](cols locationsAsyncColumns) locationsAsyncWhere[Q] { + return locationsAsyncWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Completed: mysql.Where[Q, bool](cols.Completed), + WasError: mysql.Where[Q, bool](cols.WasError), + Result: mysql.WhereNull[Q, []byte](cols.Result), + Error: mysql.WhereNull[Q, []byte](cols.Error), + CreatedTime: mysql.Where[Q, time.Time](cols.CreatedTime), + UpdatedTime: mysql.Where[Q, time.Time](cols.UpdatedTime), + CompletedTime: mysql.WhereNull[Q, time.Time](cols.CompletedTime), + } +} diff --git a/database/mcp/models/locations_callback.bob.go b/database/mcp/models/locations_callback.bob.go new file mode 100644 index 0000000..e0d87f6 --- /dev/null +++ b/database/mcp/models/locations_callback.bob.go @@ -0,0 +1,540 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" +) + +// LocationsCallback is an object representing the database table. +type LocationsCallback struct { + ID int32 `db:"id,pk,autoincr" ` + UUID string `db:"uuid" ` + URI string `db:"uri" ` + Event string `db:"event" ` + Method string `db:"method" ` + ExpectedStatus int32 `db:"expected_status" ` + Enabled bool `db:"enabled" ` + Body null.Val[string] `db:"body" ` + Headers null.Val[string] `db:"headers" ` +} + +// LocationsCallbackSlice is an alias for a slice of pointers to LocationsCallback. +// This should almost always be used instead of []*LocationsCallback. +type LocationsCallbackSlice []*LocationsCallback + +// LocationsCallbacks contains methods to work with the locations_callback table +var LocationsCallbacks = mysql.NewTablex[*LocationsCallback, LocationsCallbackSlice, *LocationsCallbackSetter]("locations_callback", buildLocationsCallbackColumns("locations_callback"), []string{"id"}) + +// LocationsCallbacksQuery is a query on the locations_callback table +type LocationsCallbacksQuery = *mysql.ViewQuery[*LocationsCallback, LocationsCallbackSlice] + +func buildLocationsCallbackColumns(alias string) locationsCallbackColumns { + return locationsCallbackColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "uuid", "uri", "event", "method", "expected_status", "enabled", "body", "headers", + ).WithParent("locations_callback"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UUID: mysql.Quote(alias, "uuid"), + URI: mysql.Quote(alias, "uri"), + Event: mysql.Quote(alias, "event"), + Method: mysql.Quote(alias, "method"), + ExpectedStatus: mysql.Quote(alias, "expected_status"), + Enabled: mysql.Quote(alias, "enabled"), + Body: mysql.Quote(alias, "body"), + Headers: mysql.Quote(alias, "headers"), + } +} + +type locationsCallbackColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UUID mysql.Expression + URI mysql.Expression + Event mysql.Expression + Method mysql.Expression + ExpectedStatus mysql.Expression + Enabled mysql.Expression + Body mysql.Expression + Headers mysql.Expression +} + +func (c locationsCallbackColumns) Alias() string { + return c.tableAlias +} + +func (locationsCallbackColumns) AliasedAs(alias string) locationsCallbackColumns { + return buildLocationsCallbackColumns(alias) +} + +// LocationsCallbackSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsCallbackSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UUID omit.Val[string] `db:"uuid" ` + URI omit.Val[string] `db:"uri" ` + Event omit.Val[string] `db:"event" ` + Method omit.Val[string] `db:"method" ` + ExpectedStatus omit.Val[int32] `db:"expected_status" ` + Enabled omit.Val[bool] `db:"enabled" ` + Body omitnull.Val[string] `db:"body" ` + Headers omitnull.Val[string] `db:"headers" ` +} + +func (s LocationsCallbackSetter) SetColumns() []string { + vals := make([]string, 0, 9) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UUID.IsValue() { + vals = append(vals, "uuid") + } + if s.URI.IsValue() { + vals = append(vals, "uri") + } + if s.Event.IsValue() { + vals = append(vals, "event") + } + if s.Method.IsValue() { + vals = append(vals, "method") + } + if s.ExpectedStatus.IsValue() { + vals = append(vals, "expected_status") + } + if s.Enabled.IsValue() { + vals = append(vals, "enabled") + } + if !s.Body.IsUnset() { + vals = append(vals, "body") + } + if !s.Headers.IsUnset() { + vals = append(vals, "headers") + } + return vals +} + +func (s LocationsCallbackSetter) Overwrite(t *LocationsCallback) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UUID.IsValue() { + t.UUID = s.UUID.MustGet() + } + if s.URI.IsValue() { + t.URI = s.URI.MustGet() + } + if s.Event.IsValue() { + t.Event = s.Event.MustGet() + } + if s.Method.IsValue() { + t.Method = s.Method.MustGet() + } + if s.ExpectedStatus.IsValue() { + t.ExpectedStatus = s.ExpectedStatus.MustGet() + } + if s.Enabled.IsValue() { + t.Enabled = s.Enabled.MustGet() + } + if !s.Body.IsUnset() { + t.Body = s.Body.MustGetNull() + } + if !s.Headers.IsUnset() { + t.Headers = s.Headers.MustGetNull() + } +} + +func (s *LocationsCallbackSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsCallbacks.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UUID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UUID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.URI.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.URI.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Event.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Event.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Method.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Method.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ExpectedStatus.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ExpectedStatus.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Enabled.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Enabled.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Body.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Body.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Headers.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Headers.MustGetNull()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsCallbackSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_callback")...) +} + +func (s LocationsCallbackSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 9) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UUID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uuid")...), + mysql.Arg(s.UUID), + }}) + } + + if s.URI.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uri")...), + mysql.Arg(s.URI), + }}) + } + + if s.Event.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "event")...), + mysql.Arg(s.Event), + }}) + } + + if s.Method.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "method")...), + mysql.Arg(s.Method), + }}) + } + + if s.ExpectedStatus.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "expected_status")...), + mysql.Arg(s.ExpectedStatus), + }}) + } + + if s.Enabled.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "enabled")...), + mysql.Arg(s.Enabled), + }}) + } + + if !s.Body.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "body")...), + mysql.Arg(s.Body), + }}) + } + + if !s.Headers.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "headers")...), + mysql.Arg(s.Headers), + }}) + } + + return exprs +} + +// FindLocationsCallback retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsCallback(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsCallback, error) { + if len(cols) == 0 { + return LocationsCallbacks.Query( + sm.Where(LocationsCallbacks.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsCallbacks.Query( + sm.Where(LocationsCallbacks.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsCallbacks.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsCallbackExists checks the presence of a single record by primary key +func LocationsCallbackExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsCallbacks.Query( + sm.Where(LocationsCallbacks.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsCallback is retrieved from the database +func (o *LocationsCallback) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsCallbacks.AfterSelectHooks.RunHooks(ctx, exec, LocationsCallbackSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsCallbacks.AfterInsertHooks.RunHooks(ctx, exec, LocationsCallbackSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsCallbacks.AfterUpdateHooks.RunHooks(ctx, exec, LocationsCallbackSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsCallbacks.AfterDeleteHooks.RunHooks(ctx, exec, LocationsCallbackSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsCallback +func (o *LocationsCallback) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsCallback) pkEQ() dialect.Expression { + return mysql.Quote("locations_callback", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsCallback +func (o *LocationsCallback) Update(ctx context.Context, exec bob.Executor, s *LocationsCallbackSetter) error { + _, err := LocationsCallbacks.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsCallback record with an executor +func (o *LocationsCallback) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsCallbacks.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsCallback using the executor +func (o *LocationsCallback) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsCallbacks.Query( + sm.Where(LocationsCallbacks.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsCallbackSlice is retrieved from the database +func (o LocationsCallbackSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsCallbacks.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsCallbacks.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsCallbacks.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsCallbacks.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsCallbackSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_callback", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsCallbackSlice) copyMatchingRows(from ...*LocationsCallback) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsCallbackSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsCallbacks.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsCallback: + o.copyMatchingRows(retrieved) + case []*LocationsCallback: + o.copyMatchingRows(retrieved...) + case LocationsCallbackSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsCallback or a slice of LocationsCallback + // then run the AfterUpdateHooks on the slice + _, err = LocationsCallbacks.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsCallbackSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsCallbacks.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsCallback: + o.copyMatchingRows(retrieved) + case []*LocationsCallback: + o.copyMatchingRows(retrieved...) + case LocationsCallbackSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsCallback or a slice of LocationsCallback + // then run the AfterDeleteHooks on the slice + _, err = LocationsCallbacks.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsCallbackSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsCallbackSetter) error { + _, err := LocationsCallbacks.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsCallbackSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsCallbacks.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsCallbackSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsCallbacks.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +type locationsCallbackWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UUID mysql.WhereMod[Q, string] + URI mysql.WhereMod[Q, string] + Event mysql.WhereMod[Q, string] + Method mysql.WhereMod[Q, string] + ExpectedStatus mysql.WhereMod[Q, int32] + Enabled mysql.WhereMod[Q, bool] + Body mysql.WhereNullMod[Q, string] + Headers mysql.WhereNullMod[Q, string] +} + +func (locationsCallbackWhere[Q]) AliasedAs(alias string) locationsCallbackWhere[Q] { + return buildLocationsCallbackWhere[Q](buildLocationsCallbackColumns(alias)) +} + +func buildLocationsCallbackWhere[Q mysql.Filterable](cols locationsCallbackColumns) locationsCallbackWhere[Q] { + return locationsCallbackWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UUID: mysql.Where[Q, string](cols.UUID), + URI: mysql.Where[Q, string](cols.URI), + Event: mysql.Where[Q, string](cols.Event), + Method: mysql.Where[Q, string](cols.Method), + ExpectedStatus: mysql.Where[Q, int32](cols.ExpectedStatus), + Enabled: mysql.Where[Q, bool](cols.Enabled), + Body: mysql.WhereNull[Q, string](cols.Body), + Headers: mysql.WhereNull[Q, string](cols.Headers), + } +} diff --git a/database/mcp/models/locations_dataverse.bob.go b/database/mcp/models/locations_dataverse.bob.go new file mode 100644 index 0000000..5842b71 --- /dev/null +++ b/database/mcp/models/locations_dataverse.bob.go @@ -0,0 +1,712 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsDataverse is an object representing the database table. +type LocationsDataverse struct { + ID int32 `db:"id,pk,autoincr" ` + Host string `db:"host" ` + APIKey string `db:"api_key" ` + AgentName string `db:"agent_name" ` + AgentType string `db:"agent_type" ` + AgentIdentifier string `db:"agent_identifier" ` + SpaceID string `db:"space_id" ` + + R locationsDataverseR `db:"-" ` +} + +// LocationsDataverseSlice is an alias for a slice of pointers to LocationsDataverse. +// This should almost always be used instead of []*LocationsDataverse. +type LocationsDataverseSlice []*LocationsDataverse + +// LocationsDataverses contains methods to work with the locations_dataverse table +var LocationsDataverses = mysql.NewTablex[*LocationsDataverse, LocationsDataverseSlice, *LocationsDataverseSetter]("locations_dataverse", buildLocationsDataverseColumns("locations_dataverse"), []string{"id"}, []string{"space_id"}) + +// LocationsDataversesQuery is a query on the locations_dataverse table +type LocationsDataversesQuery = *mysql.ViewQuery[*LocationsDataverse, LocationsDataverseSlice] + +// locationsDataverseR is where relationships are stored. +type locationsDataverseR struct { + SpaceLocationsSpace *LocationsSpace // locations_dataverse_space_id_1b94d732_fk_locations_space_uuid +} + +func buildLocationsDataverseColumns(alias string) locationsDataverseColumns { + return locationsDataverseColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "host", "api_key", "agent_name", "agent_type", "agent_identifier", "space_id", + ).WithParent("locations_dataverse"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Host: mysql.Quote(alias, "host"), + APIKey: mysql.Quote(alias, "api_key"), + AgentName: mysql.Quote(alias, "agent_name"), + AgentType: mysql.Quote(alias, "agent_type"), + AgentIdentifier: mysql.Quote(alias, "agent_identifier"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsDataverseColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Host mysql.Expression + APIKey mysql.Expression + AgentName mysql.Expression + AgentType mysql.Expression + AgentIdentifier mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsDataverseColumns) Alias() string { + return c.tableAlias +} + +func (locationsDataverseColumns) AliasedAs(alias string) locationsDataverseColumns { + return buildLocationsDataverseColumns(alias) +} + +// LocationsDataverseSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsDataverseSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Host omit.Val[string] `db:"host" ` + APIKey omit.Val[string] `db:"api_key" ` + AgentName omit.Val[string] `db:"agent_name" ` + AgentType omit.Val[string] `db:"agent_type" ` + AgentIdentifier omit.Val[string] `db:"agent_identifier" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsDataverseSetter) SetColumns() []string { + vals := make([]string, 0, 7) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Host.IsValue() { + vals = append(vals, "host") + } + if s.APIKey.IsValue() { + vals = append(vals, "api_key") + } + if s.AgentName.IsValue() { + vals = append(vals, "agent_name") + } + if s.AgentType.IsValue() { + vals = append(vals, "agent_type") + } + if s.AgentIdentifier.IsValue() { + vals = append(vals, "agent_identifier") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsDataverseSetter) Overwrite(t *LocationsDataverse) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Host.IsValue() { + t.Host = s.Host.MustGet() + } + if s.APIKey.IsValue() { + t.APIKey = s.APIKey.MustGet() + } + if s.AgentName.IsValue() { + t.AgentName = s.AgentName.MustGet() + } + if s.AgentType.IsValue() { + t.AgentType = s.AgentType.MustGet() + } + if s.AgentIdentifier.IsValue() { + t.AgentIdentifier = s.AgentIdentifier.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsDataverseSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDataverses.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Host.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Host.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.APIKey.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.APIKey.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AgentName.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AgentName.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AgentType.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AgentType.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AgentIdentifier.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AgentIdentifier.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsDataverseSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_dataverse")...) +} + +func (s LocationsDataverseSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 7) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Host.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "host")...), + mysql.Arg(s.Host), + }}) + } + + if s.APIKey.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "api_key")...), + mysql.Arg(s.APIKey), + }}) + } + + if s.AgentName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "agent_name")...), + mysql.Arg(s.AgentName), + }}) + } + + if s.AgentType.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "agent_type")...), + mysql.Arg(s.AgentType), + }}) + } + + if s.AgentIdentifier.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "agent_identifier")...), + mysql.Arg(s.AgentIdentifier), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsDataverse retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsDataverse(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsDataverse, error) { + if len(cols) == 0 { + return LocationsDataverses.Query( + sm.Where(LocationsDataverses.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsDataverses.Query( + sm.Where(LocationsDataverses.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsDataverses.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsDataverseExists checks the presence of a single record by primary key +func LocationsDataverseExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsDataverses.Query( + sm.Where(LocationsDataverses.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsDataverse is retrieved from the database +func (o *LocationsDataverse) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsDataverses.AfterSelectHooks.RunHooks(ctx, exec, LocationsDataverseSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsDataverses.AfterInsertHooks.RunHooks(ctx, exec, LocationsDataverseSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsDataverses.AfterUpdateHooks.RunHooks(ctx, exec, LocationsDataverseSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsDataverses.AfterDeleteHooks.RunHooks(ctx, exec, LocationsDataverseSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsDataverse +func (o *LocationsDataverse) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsDataverse) pkEQ() dialect.Expression { + return mysql.Quote("locations_dataverse", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsDataverse +func (o *LocationsDataverse) Update(ctx context.Context, exec bob.Executor, s *LocationsDataverseSetter) error { + _, err := LocationsDataverses.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsDataverse record with an executor +func (o *LocationsDataverse) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsDataverses.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsDataverse using the executor +func (o *LocationsDataverse) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsDataverses.Query( + sm.Where(LocationsDataverses.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsDataverseSlice is retrieved from the database +func (o LocationsDataverseSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsDataverses.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsDataverses.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsDataverses.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsDataverses.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsDataverseSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_dataverse", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsDataverseSlice) copyMatchingRows(from ...*LocationsDataverse) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsDataverseSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDataverses.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsDataverse: + o.copyMatchingRows(retrieved) + case []*LocationsDataverse: + o.copyMatchingRows(retrieved...) + case LocationsDataverseSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsDataverse or a slice of LocationsDataverse + // then run the AfterUpdateHooks on the slice + _, err = LocationsDataverses.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsDataverseSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDataverses.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsDataverse: + o.copyMatchingRows(retrieved) + case []*LocationsDataverse: + o.copyMatchingRows(retrieved...) + case LocationsDataverseSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsDataverse or a slice of LocationsDataverse + // then run the AfterDeleteHooks on the slice + _, err = LocationsDataverses.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsDataverseSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsDataverseSetter) error { + _, err := LocationsDataverses.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsDataverseSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsDataverses.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsDataverseSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsDataverses.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsDataverse) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsDataverseSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsDataverseSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsDataverse0 *LocationsDataverse, locationsSpace1 *LocationsSpace) (*LocationsDataverse, error) { + setter := &LocationsDataverseSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsDataverse0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsDataverseSpaceLocationsSpace0: %w", err) + } + + return locationsDataverse0, nil +} + +func (locationsDataverse0 *LocationsDataverse) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsDataverseSpaceLocationsSpace0(ctx, exec, 1, locationsDataverse0, locationsSpace1) + if err != nil { + return err + } + + locationsDataverse0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsDataverse = locationsDataverse0 + + return nil +} + +func (locationsDataverse0 *LocationsDataverse) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsDataverseSpaceLocationsSpace0(ctx, exec, 1, locationsDataverse0, locationsSpace1) + if err != nil { + return err + } + + locationsDataverse0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsDataverse = locationsDataverse0 + + return nil +} + +type locationsDataverseWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Host mysql.WhereMod[Q, string] + APIKey mysql.WhereMod[Q, string] + AgentName mysql.WhereMod[Q, string] + AgentType mysql.WhereMod[Q, string] + AgentIdentifier mysql.WhereMod[Q, string] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsDataverseWhere[Q]) AliasedAs(alias string) locationsDataverseWhere[Q] { + return buildLocationsDataverseWhere[Q](buildLocationsDataverseColumns(alias)) +} + +func buildLocationsDataverseWhere[Q mysql.Filterable](cols locationsDataverseColumns) locationsDataverseWhere[Q] { + return locationsDataverseWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Host: mysql.Where[Q, string](cols.Host), + APIKey: mysql.Where[Q, string](cols.APIKey), + AgentName: mysql.Where[Q, string](cols.AgentName), + AgentType: mysql.Where[Q, string](cols.AgentType), + AgentIdentifier: mysql.Where[Q, string](cols.AgentIdentifier), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsDataverse) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsDataverse cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsDataverse = o + } + return nil + default: + return fmt.Errorf("locationsDataverse has no relationship %q", name) + } +} + +type locationsDataversePreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsDataversePreloader() locationsDataversePreloader { + return locationsDataversePreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsDataverses, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsDataverseThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsDataverseThenLoader[Q orm.Loadable]() locationsDataverseThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsDataverseThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsDataverse's SpaceLocationsSpace into the .R struct +func (o *LocationsDataverse) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsDataverse = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsDataverse's SpaceLocationsSpace into the .R struct +func (os LocationsDataverseSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsDataverse = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsDataverseJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsDataverseJoins[Q]) aliasedAs(alias string) locationsDataverseJoins[Q] { + return buildLocationsDataverseJoins[Q](buildLocationsDataverseColumns(alias), j.typ) +} + +func buildLocationsDataverseJoins[Q dialect.Joinable](cols locationsDataverseColumns, typ string) locationsDataverseJoins[Q] { + return locationsDataverseJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_dspace.bob.go b/database/mcp/models/locations_dspace.bob.go new file mode 100644 index 0000000..1bbb03c --- /dev/null +++ b/database/mcp/models/locations_dspace.bob.go @@ -0,0 +1,714 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsDspace is an object representing the database table. +type LocationsDspace struct { + ID int32 `db:"id,pk,autoincr" ` + SDIri string `db:"sd_iri" ` + User string `db:"user" ` + Password string `db:"password" ` + SpaceID string `db:"space_id" ` + MetadataPolicy null.Val[string] `db:"metadata_policy" ` + ArchiveFormat string `db:"archive_format" ` + + R locationsDspaceR `db:"-" ` +} + +// LocationsDspaceSlice is an alias for a slice of pointers to LocationsDspace. +// This should almost always be used instead of []*LocationsDspace. +type LocationsDspaceSlice []*LocationsDspace + +// LocationsDspaces contains methods to work with the locations_dspace table +var LocationsDspaces = mysql.NewTablex[*LocationsDspace, LocationsDspaceSlice, *LocationsDspaceSetter]("locations_dspace", buildLocationsDspaceColumns("locations_dspace"), []string{"id"}, []string{"space_id"}) + +// LocationsDspacesQuery is a query on the locations_dspace table +type LocationsDspacesQuery = *mysql.ViewQuery[*LocationsDspace, LocationsDspaceSlice] + +// locationsDspaceR is where relationships are stored. +type locationsDspaceR struct { + SpaceLocationsSpace *LocationsSpace // locations_dspace_space_id_e1c12ce1_fk_locations_space_uuid +} + +func buildLocationsDspaceColumns(alias string) locationsDspaceColumns { + return locationsDspaceColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "sd_iri", "user", "password", "space_id", "metadata_policy", "archive_format", + ).WithParent("locations_dspace"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + SDIri: mysql.Quote(alias, "sd_iri"), + User: mysql.Quote(alias, "user"), + Password: mysql.Quote(alias, "password"), + SpaceID: mysql.Quote(alias, "space_id"), + MetadataPolicy: mysql.Quote(alias, "metadata_policy"), + ArchiveFormat: mysql.Quote(alias, "archive_format"), + } +} + +type locationsDspaceColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + SDIri mysql.Expression + User mysql.Expression + Password mysql.Expression + SpaceID mysql.Expression + MetadataPolicy mysql.Expression + ArchiveFormat mysql.Expression +} + +func (c locationsDspaceColumns) Alias() string { + return c.tableAlias +} + +func (locationsDspaceColumns) AliasedAs(alias string) locationsDspaceColumns { + return buildLocationsDspaceColumns(alias) +} + +// LocationsDspaceSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsDspaceSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + SDIri omit.Val[string] `db:"sd_iri" ` + User omit.Val[string] `db:"user" ` + Password omit.Val[string] `db:"password" ` + SpaceID omit.Val[string] `db:"space_id" ` + MetadataPolicy omitnull.Val[string] `db:"metadata_policy" ` + ArchiveFormat omit.Val[string] `db:"archive_format" ` +} + +func (s LocationsDspaceSetter) SetColumns() []string { + vals := make([]string, 0, 7) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.SDIri.IsValue() { + vals = append(vals, "sd_iri") + } + if s.User.IsValue() { + vals = append(vals, "user") + } + if s.Password.IsValue() { + vals = append(vals, "password") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + if !s.MetadataPolicy.IsUnset() { + vals = append(vals, "metadata_policy") + } + if s.ArchiveFormat.IsValue() { + vals = append(vals, "archive_format") + } + return vals +} + +func (s LocationsDspaceSetter) Overwrite(t *LocationsDspace) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.SDIri.IsValue() { + t.SDIri = s.SDIri.MustGet() + } + if s.User.IsValue() { + t.User = s.User.MustGet() + } + if s.Password.IsValue() { + t.Password = s.Password.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } + if !s.MetadataPolicy.IsUnset() { + t.MetadataPolicy = s.MetadataPolicy.MustGetNull() + } + if s.ArchiveFormat.IsValue() { + t.ArchiveFormat = s.ArchiveFormat.MustGet() + } +} + +func (s *LocationsDspaceSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDspaces.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SDIri.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SDIri.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.User.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.User.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Password.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Password.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.MetadataPolicy.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.MetadataPolicy.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ArchiveFormat.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ArchiveFormat.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsDspaceSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_dspace")...) +} + +func (s LocationsDspaceSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 7) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.SDIri.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "sd_iri")...), + mysql.Arg(s.SDIri), + }}) + } + + if s.User.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "user")...), + mysql.Arg(s.User), + }}) + } + + if s.Password.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "password")...), + mysql.Arg(s.Password), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + if !s.MetadataPolicy.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "metadata_policy")...), + mysql.Arg(s.MetadataPolicy), + }}) + } + + if s.ArchiveFormat.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "archive_format")...), + mysql.Arg(s.ArchiveFormat), + }}) + } + + return exprs +} + +// FindLocationsDspace retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsDspace(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsDspace, error) { + if len(cols) == 0 { + return LocationsDspaces.Query( + sm.Where(LocationsDspaces.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsDspaces.Query( + sm.Where(LocationsDspaces.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsDspaces.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsDspaceExists checks the presence of a single record by primary key +func LocationsDspaceExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsDspaces.Query( + sm.Where(LocationsDspaces.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsDspace is retrieved from the database +func (o *LocationsDspace) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsDspaces.AfterSelectHooks.RunHooks(ctx, exec, LocationsDspaceSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsDspaces.AfterInsertHooks.RunHooks(ctx, exec, LocationsDspaceSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsDspaces.AfterUpdateHooks.RunHooks(ctx, exec, LocationsDspaceSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsDspaces.AfterDeleteHooks.RunHooks(ctx, exec, LocationsDspaceSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsDspace +func (o *LocationsDspace) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsDspace) pkEQ() dialect.Expression { + return mysql.Quote("locations_dspace", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsDspace +func (o *LocationsDspace) Update(ctx context.Context, exec bob.Executor, s *LocationsDspaceSetter) error { + _, err := LocationsDspaces.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsDspace record with an executor +func (o *LocationsDspace) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsDspaces.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsDspace using the executor +func (o *LocationsDspace) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsDspaces.Query( + sm.Where(LocationsDspaces.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsDspaceSlice is retrieved from the database +func (o LocationsDspaceSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsDspaces.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsDspaces.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsDspaces.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsDspaces.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsDspaceSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_dspace", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsDspaceSlice) copyMatchingRows(from ...*LocationsDspace) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsDspaceSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDspaces.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsDspace: + o.copyMatchingRows(retrieved) + case []*LocationsDspace: + o.copyMatchingRows(retrieved...) + case LocationsDspaceSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsDspace or a slice of LocationsDspace + // then run the AfterUpdateHooks on the slice + _, err = LocationsDspaces.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsDspaceSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDspaces.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsDspace: + o.copyMatchingRows(retrieved) + case []*LocationsDspace: + o.copyMatchingRows(retrieved...) + case LocationsDspaceSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsDspace or a slice of LocationsDspace + // then run the AfterDeleteHooks on the slice + _, err = LocationsDspaces.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsDspaceSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsDspaceSetter) error { + _, err := LocationsDspaces.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsDspaceSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsDspaces.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsDspaceSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsDspaces.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsDspace) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsDspaceSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsDspaceSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsDspace0 *LocationsDspace, locationsSpace1 *LocationsSpace) (*LocationsDspace, error) { + setter := &LocationsDspaceSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsDspace0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsDspaceSpaceLocationsSpace0: %w", err) + } + + return locationsDspace0, nil +} + +func (locationsDspace0 *LocationsDspace) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsDspaceSpaceLocationsSpace0(ctx, exec, 1, locationsDspace0, locationsSpace1) + if err != nil { + return err + } + + locationsDspace0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsDspace = locationsDspace0 + + return nil +} + +func (locationsDspace0 *LocationsDspace) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsDspaceSpaceLocationsSpace0(ctx, exec, 1, locationsDspace0, locationsSpace1) + if err != nil { + return err + } + + locationsDspace0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsDspace = locationsDspace0 + + return nil +} + +type locationsDspaceWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + SDIri mysql.WhereMod[Q, string] + User mysql.WhereMod[Q, string] + Password mysql.WhereMod[Q, string] + SpaceID mysql.WhereMod[Q, string] + MetadataPolicy mysql.WhereNullMod[Q, string] + ArchiveFormat mysql.WhereMod[Q, string] +} + +func (locationsDspaceWhere[Q]) AliasedAs(alias string) locationsDspaceWhere[Q] { + return buildLocationsDspaceWhere[Q](buildLocationsDspaceColumns(alias)) +} + +func buildLocationsDspaceWhere[Q mysql.Filterable](cols locationsDspaceColumns) locationsDspaceWhere[Q] { + return locationsDspaceWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + SDIri: mysql.Where[Q, string](cols.SDIri), + User: mysql.Where[Q, string](cols.User), + Password: mysql.Where[Q, string](cols.Password), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + MetadataPolicy: mysql.WhereNull[Q, string](cols.MetadataPolicy), + ArchiveFormat: mysql.Where[Q, string](cols.ArchiveFormat), + } +} + +func (o *LocationsDspace) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsDspace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsDspace = o + } + return nil + default: + return fmt.Errorf("locationsDspace has no relationship %q", name) + } +} + +type locationsDspacePreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsDspacePreloader() locationsDspacePreloader { + return locationsDspacePreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsDspaces, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsDspaceThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsDspaceThenLoader[Q orm.Loadable]() locationsDspaceThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsDspaceThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsDspace's SpaceLocationsSpace into the .R struct +func (o *LocationsDspace) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsDspace = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsDspace's SpaceLocationsSpace into the .R struct +func (os LocationsDspaceSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsDspace = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsDspaceJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsDspaceJoins[Q]) aliasedAs(alias string) locationsDspaceJoins[Q] { + return buildLocationsDspaceJoins[Q](buildLocationsDspaceColumns(alias), j.typ) +} + +func buildLocationsDspaceJoins[Q dialect.Joinable](cols locationsDspaceColumns, typ string) locationsDspaceJoins[Q] { + return locationsDspaceJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_dspacerest.bob.go b/database/mcp/models/locations_dspacerest.bob.go new file mode 100644 index 0000000..c57c864 --- /dev/null +++ b/database/mcp/models/locations_dspacerest.bob.go @@ -0,0 +1,880 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsDspacerest is an object representing the database table. +type LocationsDspacerest struct { + ID int32 `db:"id,pk,autoincr" ` + DSRestURL string `db:"ds_rest_url" ` + DSUser string `db:"ds_user" ` + DSPassword string `db:"ds_password" ` + DSDipCollection string `db:"ds_dip_collection" ` + DSAipCollection string `db:"ds_aip_collection" ` + AsURL string `db:"as_url" ` + AsUser string `db:"as_user" ` + AsPassword string `db:"as_password" ` + AsRepository string `db:"as_repository" ` + AsArchivalObject string `db:"as_archival_object" ` + VerifySSL bool `db:"verify_ssl" ` + UploadToTSM bool `db:"upload_to_tsm" ` + SpaceID string `db:"space_id" ` + + R locationsDspacerestR `db:"-" ` +} + +// LocationsDspacerestSlice is an alias for a slice of pointers to LocationsDspacerest. +// This should almost always be used instead of []*LocationsDspacerest. +type LocationsDspacerestSlice []*LocationsDspacerest + +// LocationsDspacerests contains methods to work with the locations_dspacerest table +var LocationsDspacerests = mysql.NewTablex[*LocationsDspacerest, LocationsDspacerestSlice, *LocationsDspacerestSetter]("locations_dspacerest", buildLocationsDspacerestColumns("locations_dspacerest"), []string{"id"}, []string{"space_id"}) + +// LocationsDspacerestsQuery is a query on the locations_dspacerest table +type LocationsDspacerestsQuery = *mysql.ViewQuery[*LocationsDspacerest, LocationsDspacerestSlice] + +// locationsDspacerestR is where relationships are stored. +type locationsDspacerestR struct { + SpaceLocationsSpace *LocationsSpace // locations_dspacerest_space_id_6ae6a82b_fk_locations_space_uuid +} + +func buildLocationsDspacerestColumns(alias string) locationsDspacerestColumns { + return locationsDspacerestColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "ds_rest_url", "ds_user", "ds_password", "ds_dip_collection", "ds_aip_collection", "as_url", "as_user", "as_password", "as_repository", "as_archival_object", "verify_ssl", "upload_to_tsm", "space_id", + ).WithParent("locations_dspacerest"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + DSRestURL: mysql.Quote(alias, "ds_rest_url"), + DSUser: mysql.Quote(alias, "ds_user"), + DSPassword: mysql.Quote(alias, "ds_password"), + DSDipCollection: mysql.Quote(alias, "ds_dip_collection"), + DSAipCollection: mysql.Quote(alias, "ds_aip_collection"), + AsURL: mysql.Quote(alias, "as_url"), + AsUser: mysql.Quote(alias, "as_user"), + AsPassword: mysql.Quote(alias, "as_password"), + AsRepository: mysql.Quote(alias, "as_repository"), + AsArchivalObject: mysql.Quote(alias, "as_archival_object"), + VerifySSL: mysql.Quote(alias, "verify_ssl"), + UploadToTSM: mysql.Quote(alias, "upload_to_tsm"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsDspacerestColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + DSRestURL mysql.Expression + DSUser mysql.Expression + DSPassword mysql.Expression + DSDipCollection mysql.Expression + DSAipCollection mysql.Expression + AsURL mysql.Expression + AsUser mysql.Expression + AsPassword mysql.Expression + AsRepository mysql.Expression + AsArchivalObject mysql.Expression + VerifySSL mysql.Expression + UploadToTSM mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsDspacerestColumns) Alias() string { + return c.tableAlias +} + +func (locationsDspacerestColumns) AliasedAs(alias string) locationsDspacerestColumns { + return buildLocationsDspacerestColumns(alias) +} + +// LocationsDspacerestSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsDspacerestSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + DSRestURL omit.Val[string] `db:"ds_rest_url" ` + DSUser omit.Val[string] `db:"ds_user" ` + DSPassword omit.Val[string] `db:"ds_password" ` + DSDipCollection omit.Val[string] `db:"ds_dip_collection" ` + DSAipCollection omit.Val[string] `db:"ds_aip_collection" ` + AsURL omit.Val[string] `db:"as_url" ` + AsUser omit.Val[string] `db:"as_user" ` + AsPassword omit.Val[string] `db:"as_password" ` + AsRepository omit.Val[string] `db:"as_repository" ` + AsArchivalObject omit.Val[string] `db:"as_archival_object" ` + VerifySSL omit.Val[bool] `db:"verify_ssl" ` + UploadToTSM omit.Val[bool] `db:"upload_to_tsm" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsDspacerestSetter) SetColumns() []string { + vals := make([]string, 0, 14) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.DSRestURL.IsValue() { + vals = append(vals, "ds_rest_url") + } + if s.DSUser.IsValue() { + vals = append(vals, "ds_user") + } + if s.DSPassword.IsValue() { + vals = append(vals, "ds_password") + } + if s.DSDipCollection.IsValue() { + vals = append(vals, "ds_dip_collection") + } + if s.DSAipCollection.IsValue() { + vals = append(vals, "ds_aip_collection") + } + if s.AsURL.IsValue() { + vals = append(vals, "as_url") + } + if s.AsUser.IsValue() { + vals = append(vals, "as_user") + } + if s.AsPassword.IsValue() { + vals = append(vals, "as_password") + } + if s.AsRepository.IsValue() { + vals = append(vals, "as_repository") + } + if s.AsArchivalObject.IsValue() { + vals = append(vals, "as_archival_object") + } + if s.VerifySSL.IsValue() { + vals = append(vals, "verify_ssl") + } + if s.UploadToTSM.IsValue() { + vals = append(vals, "upload_to_tsm") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsDspacerestSetter) Overwrite(t *LocationsDspacerest) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.DSRestURL.IsValue() { + t.DSRestURL = s.DSRestURL.MustGet() + } + if s.DSUser.IsValue() { + t.DSUser = s.DSUser.MustGet() + } + if s.DSPassword.IsValue() { + t.DSPassword = s.DSPassword.MustGet() + } + if s.DSDipCollection.IsValue() { + t.DSDipCollection = s.DSDipCollection.MustGet() + } + if s.DSAipCollection.IsValue() { + t.DSAipCollection = s.DSAipCollection.MustGet() + } + if s.AsURL.IsValue() { + t.AsURL = s.AsURL.MustGet() + } + if s.AsUser.IsValue() { + t.AsUser = s.AsUser.MustGet() + } + if s.AsPassword.IsValue() { + t.AsPassword = s.AsPassword.MustGet() + } + if s.AsRepository.IsValue() { + t.AsRepository = s.AsRepository.MustGet() + } + if s.AsArchivalObject.IsValue() { + t.AsArchivalObject = s.AsArchivalObject.MustGet() + } + if s.VerifySSL.IsValue() { + t.VerifySSL = s.VerifySSL.MustGet() + } + if s.UploadToTSM.IsValue() { + t.UploadToTSM = s.UploadToTSM.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsDspacerestSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDspacerests.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DSRestURL.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DSRestURL.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DSUser.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DSUser.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DSPassword.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DSPassword.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DSDipCollection.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DSDipCollection.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DSAipCollection.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DSAipCollection.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AsURL.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AsURL.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AsUser.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AsUser.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AsPassword.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AsPassword.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AsRepository.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AsRepository.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AsArchivalObject.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AsArchivalObject.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.VerifySSL.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.VerifySSL.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UploadToTSM.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UploadToTSM.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsDspacerestSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_dspacerest")...) +} + +func (s LocationsDspacerestSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 14) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.DSRestURL.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "ds_rest_url")...), + mysql.Arg(s.DSRestURL), + }}) + } + + if s.DSUser.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "ds_user")...), + mysql.Arg(s.DSUser), + }}) + } + + if s.DSPassword.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "ds_password")...), + mysql.Arg(s.DSPassword), + }}) + } + + if s.DSDipCollection.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "ds_dip_collection")...), + mysql.Arg(s.DSDipCollection), + }}) + } + + if s.DSAipCollection.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "ds_aip_collection")...), + mysql.Arg(s.DSAipCollection), + }}) + } + + if s.AsURL.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "as_url")...), + mysql.Arg(s.AsURL), + }}) + } + + if s.AsUser.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "as_user")...), + mysql.Arg(s.AsUser), + }}) + } + + if s.AsPassword.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "as_password")...), + mysql.Arg(s.AsPassword), + }}) + } + + if s.AsRepository.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "as_repository")...), + mysql.Arg(s.AsRepository), + }}) + } + + if s.AsArchivalObject.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "as_archival_object")...), + mysql.Arg(s.AsArchivalObject), + }}) + } + + if s.VerifySSL.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "verify_ssl")...), + mysql.Arg(s.VerifySSL), + }}) + } + + if s.UploadToTSM.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "upload_to_tsm")...), + mysql.Arg(s.UploadToTSM), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsDspacerest retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsDspacerest(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsDspacerest, error) { + if len(cols) == 0 { + return LocationsDspacerests.Query( + sm.Where(LocationsDspacerests.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsDspacerests.Query( + sm.Where(LocationsDspacerests.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsDspacerests.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsDspacerestExists checks the presence of a single record by primary key +func LocationsDspacerestExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsDspacerests.Query( + sm.Where(LocationsDspacerests.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsDspacerest is retrieved from the database +func (o *LocationsDspacerest) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsDspacerests.AfterSelectHooks.RunHooks(ctx, exec, LocationsDspacerestSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsDspacerests.AfterInsertHooks.RunHooks(ctx, exec, LocationsDspacerestSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsDspacerests.AfterUpdateHooks.RunHooks(ctx, exec, LocationsDspacerestSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsDspacerests.AfterDeleteHooks.RunHooks(ctx, exec, LocationsDspacerestSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsDspacerest +func (o *LocationsDspacerest) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsDspacerest) pkEQ() dialect.Expression { + return mysql.Quote("locations_dspacerest", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsDspacerest +func (o *LocationsDspacerest) Update(ctx context.Context, exec bob.Executor, s *LocationsDspacerestSetter) error { + _, err := LocationsDspacerests.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsDspacerest record with an executor +func (o *LocationsDspacerest) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsDspacerests.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsDspacerest using the executor +func (o *LocationsDspacerest) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsDspacerests.Query( + sm.Where(LocationsDspacerests.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsDspacerestSlice is retrieved from the database +func (o LocationsDspacerestSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsDspacerests.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsDspacerests.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsDspacerests.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsDspacerests.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsDspacerestSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_dspacerest", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsDspacerestSlice) copyMatchingRows(from ...*LocationsDspacerest) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsDspacerestSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDspacerests.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsDspacerest: + o.copyMatchingRows(retrieved) + case []*LocationsDspacerest: + o.copyMatchingRows(retrieved...) + case LocationsDspacerestSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsDspacerest or a slice of LocationsDspacerest + // then run the AfterUpdateHooks on the slice + _, err = LocationsDspacerests.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsDspacerestSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDspacerests.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsDspacerest: + o.copyMatchingRows(retrieved) + case []*LocationsDspacerest: + o.copyMatchingRows(retrieved...) + case LocationsDspacerestSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsDspacerest or a slice of LocationsDspacerest + // then run the AfterDeleteHooks on the slice + _, err = LocationsDspacerests.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsDspacerestSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsDspacerestSetter) error { + _, err := LocationsDspacerests.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsDspacerestSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsDspacerests.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsDspacerestSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsDspacerests.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsDspacerest) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsDspacerestSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsDspacerestSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsDspacerest0 *LocationsDspacerest, locationsSpace1 *LocationsSpace) (*LocationsDspacerest, error) { + setter := &LocationsDspacerestSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsDspacerest0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsDspacerestSpaceLocationsSpace0: %w", err) + } + + return locationsDspacerest0, nil +} + +func (locationsDspacerest0 *LocationsDspacerest) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsDspacerestSpaceLocationsSpace0(ctx, exec, 1, locationsDspacerest0, locationsSpace1) + if err != nil { + return err + } + + locationsDspacerest0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsDspacerest = locationsDspacerest0 + + return nil +} + +func (locationsDspacerest0 *LocationsDspacerest) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsDspacerestSpaceLocationsSpace0(ctx, exec, 1, locationsDspacerest0, locationsSpace1) + if err != nil { + return err + } + + locationsDspacerest0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsDspacerest = locationsDspacerest0 + + return nil +} + +type locationsDspacerestWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + DSRestURL mysql.WhereMod[Q, string] + DSUser mysql.WhereMod[Q, string] + DSPassword mysql.WhereMod[Q, string] + DSDipCollection mysql.WhereMod[Q, string] + DSAipCollection mysql.WhereMod[Q, string] + AsURL mysql.WhereMod[Q, string] + AsUser mysql.WhereMod[Q, string] + AsPassword mysql.WhereMod[Q, string] + AsRepository mysql.WhereMod[Q, string] + AsArchivalObject mysql.WhereMod[Q, string] + VerifySSL mysql.WhereMod[Q, bool] + UploadToTSM mysql.WhereMod[Q, bool] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsDspacerestWhere[Q]) AliasedAs(alias string) locationsDspacerestWhere[Q] { + return buildLocationsDspacerestWhere[Q](buildLocationsDspacerestColumns(alias)) +} + +func buildLocationsDspacerestWhere[Q mysql.Filterable](cols locationsDspacerestColumns) locationsDspacerestWhere[Q] { + return locationsDspacerestWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + DSRestURL: mysql.Where[Q, string](cols.DSRestURL), + DSUser: mysql.Where[Q, string](cols.DSUser), + DSPassword: mysql.Where[Q, string](cols.DSPassword), + DSDipCollection: mysql.Where[Q, string](cols.DSDipCollection), + DSAipCollection: mysql.Where[Q, string](cols.DSAipCollection), + AsURL: mysql.Where[Q, string](cols.AsURL), + AsUser: mysql.Where[Q, string](cols.AsUser), + AsPassword: mysql.Where[Q, string](cols.AsPassword), + AsRepository: mysql.Where[Q, string](cols.AsRepository), + AsArchivalObject: mysql.Where[Q, string](cols.AsArchivalObject), + VerifySSL: mysql.Where[Q, bool](cols.VerifySSL), + UploadToTSM: mysql.Where[Q, bool](cols.UploadToTSM), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsDspacerest) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsDspacerest cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsDspacerest = o + } + return nil + default: + return fmt.Errorf("locationsDspacerest has no relationship %q", name) + } +} + +type locationsDspacerestPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsDspacerestPreloader() locationsDspacerestPreloader { + return locationsDspacerestPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsDspacerests, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsDspacerestThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsDspacerestThenLoader[Q orm.Loadable]() locationsDspacerestThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsDspacerestThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsDspacerest's SpaceLocationsSpace into the .R struct +func (o *LocationsDspacerest) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsDspacerest = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsDspacerest's SpaceLocationsSpace into the .R struct +func (os LocationsDspacerestSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsDspacerest = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsDspacerestJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsDspacerestJoins[Q]) aliasedAs(alias string) locationsDspacerestJoins[Q] { + return buildLocationsDspacerestJoins[Q](buildLocationsDspacerestColumns(alias), j.typ) +} + +func buildLocationsDspacerestJoins[Q dialect.Joinable](cols locationsDspacerestColumns, typ string) locationsDspacerestJoins[Q] { + return locationsDspacerestJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_duracloud.bob.go b/database/mcp/models/locations_duracloud.bob.go new file mode 100644 index 0000000..c4fa324 --- /dev/null +++ b/database/mcp/models/locations_duracloud.bob.go @@ -0,0 +1,688 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsDuracloud is an object representing the database table. +type LocationsDuracloud struct { + ID int32 `db:"id,pk,autoincr" ` + Host string `db:"host" ` + User string `db:"user" ` + Password string `db:"password" ` + Duraspace string `db:"duraspace" ` + SpaceID string `db:"space_id" ` + + R locationsDuracloudR `db:"-" ` +} + +// LocationsDuracloudSlice is an alias for a slice of pointers to LocationsDuracloud. +// This should almost always be used instead of []*LocationsDuracloud. +type LocationsDuracloudSlice []*LocationsDuracloud + +// LocationsDuraclouds contains methods to work with the locations_duracloud table +var LocationsDuraclouds = mysql.NewTablex[*LocationsDuracloud, LocationsDuracloudSlice, *LocationsDuracloudSetter]("locations_duracloud", buildLocationsDuracloudColumns("locations_duracloud"), []string{"id"}, []string{"space_id"}) + +// LocationsDuracloudsQuery is a query on the locations_duracloud table +type LocationsDuracloudsQuery = *mysql.ViewQuery[*LocationsDuracloud, LocationsDuracloudSlice] + +// locationsDuracloudR is where relationships are stored. +type locationsDuracloudR struct { + SpaceLocationsSpace *LocationsSpace // locations_duracloud_space_id_753df0f2_fk_locations_space_uuid +} + +func buildLocationsDuracloudColumns(alias string) locationsDuracloudColumns { + return locationsDuracloudColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "host", "user", "password", "duraspace", "space_id", + ).WithParent("locations_duracloud"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Host: mysql.Quote(alias, "host"), + User: mysql.Quote(alias, "user"), + Password: mysql.Quote(alias, "password"), + Duraspace: mysql.Quote(alias, "duraspace"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsDuracloudColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Host mysql.Expression + User mysql.Expression + Password mysql.Expression + Duraspace mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsDuracloudColumns) Alias() string { + return c.tableAlias +} + +func (locationsDuracloudColumns) AliasedAs(alias string) locationsDuracloudColumns { + return buildLocationsDuracloudColumns(alias) +} + +// LocationsDuracloudSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsDuracloudSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Host omit.Val[string] `db:"host" ` + User omit.Val[string] `db:"user" ` + Password omit.Val[string] `db:"password" ` + Duraspace omit.Val[string] `db:"duraspace" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsDuracloudSetter) SetColumns() []string { + vals := make([]string, 0, 6) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Host.IsValue() { + vals = append(vals, "host") + } + if s.User.IsValue() { + vals = append(vals, "user") + } + if s.Password.IsValue() { + vals = append(vals, "password") + } + if s.Duraspace.IsValue() { + vals = append(vals, "duraspace") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsDuracloudSetter) Overwrite(t *LocationsDuracloud) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Host.IsValue() { + t.Host = s.Host.MustGet() + } + if s.User.IsValue() { + t.User = s.User.MustGet() + } + if s.Password.IsValue() { + t.Password = s.Password.MustGet() + } + if s.Duraspace.IsValue() { + t.Duraspace = s.Duraspace.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsDuracloudSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDuraclouds.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Host.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Host.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.User.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.User.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Password.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Password.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Duraspace.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Duraspace.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsDuracloudSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_duracloud")...) +} + +func (s LocationsDuracloudSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 6) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Host.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "host")...), + mysql.Arg(s.Host), + }}) + } + + if s.User.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "user")...), + mysql.Arg(s.User), + }}) + } + + if s.Password.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "password")...), + mysql.Arg(s.Password), + }}) + } + + if s.Duraspace.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "duraspace")...), + mysql.Arg(s.Duraspace), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsDuracloud retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsDuracloud(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsDuracloud, error) { + if len(cols) == 0 { + return LocationsDuraclouds.Query( + sm.Where(LocationsDuraclouds.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsDuraclouds.Query( + sm.Where(LocationsDuraclouds.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsDuraclouds.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsDuracloudExists checks the presence of a single record by primary key +func LocationsDuracloudExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsDuraclouds.Query( + sm.Where(LocationsDuraclouds.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsDuracloud is retrieved from the database +func (o *LocationsDuracloud) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsDuraclouds.AfterSelectHooks.RunHooks(ctx, exec, LocationsDuracloudSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsDuraclouds.AfterInsertHooks.RunHooks(ctx, exec, LocationsDuracloudSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsDuraclouds.AfterUpdateHooks.RunHooks(ctx, exec, LocationsDuracloudSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsDuraclouds.AfterDeleteHooks.RunHooks(ctx, exec, LocationsDuracloudSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsDuracloud +func (o *LocationsDuracloud) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsDuracloud) pkEQ() dialect.Expression { + return mysql.Quote("locations_duracloud", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsDuracloud +func (o *LocationsDuracloud) Update(ctx context.Context, exec bob.Executor, s *LocationsDuracloudSetter) error { + _, err := LocationsDuraclouds.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsDuracloud record with an executor +func (o *LocationsDuracloud) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsDuraclouds.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsDuracloud using the executor +func (o *LocationsDuracloud) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsDuraclouds.Query( + sm.Where(LocationsDuraclouds.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsDuracloudSlice is retrieved from the database +func (o LocationsDuracloudSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsDuraclouds.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsDuraclouds.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsDuraclouds.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsDuraclouds.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsDuracloudSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_duracloud", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsDuracloudSlice) copyMatchingRows(from ...*LocationsDuracloud) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsDuracloudSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDuraclouds.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsDuracloud: + o.copyMatchingRows(retrieved) + case []*LocationsDuracloud: + o.copyMatchingRows(retrieved...) + case LocationsDuracloudSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsDuracloud or a slice of LocationsDuracloud + // then run the AfterUpdateHooks on the slice + _, err = LocationsDuraclouds.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsDuracloudSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDuraclouds.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsDuracloud: + o.copyMatchingRows(retrieved) + case []*LocationsDuracloud: + o.copyMatchingRows(retrieved...) + case LocationsDuracloudSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsDuracloud or a slice of LocationsDuracloud + // then run the AfterDeleteHooks on the slice + _, err = LocationsDuraclouds.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsDuracloudSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsDuracloudSetter) error { + _, err := LocationsDuraclouds.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsDuracloudSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsDuraclouds.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsDuracloudSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsDuraclouds.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsDuracloud) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsDuracloudSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsDuracloudSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsDuracloud0 *LocationsDuracloud, locationsSpace1 *LocationsSpace) (*LocationsDuracloud, error) { + setter := &LocationsDuracloudSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsDuracloud0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsDuracloudSpaceLocationsSpace0: %w", err) + } + + return locationsDuracloud0, nil +} + +func (locationsDuracloud0 *LocationsDuracloud) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsDuracloudSpaceLocationsSpace0(ctx, exec, 1, locationsDuracloud0, locationsSpace1) + if err != nil { + return err + } + + locationsDuracloud0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsDuracloud = locationsDuracloud0 + + return nil +} + +func (locationsDuracloud0 *LocationsDuracloud) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsDuracloudSpaceLocationsSpace0(ctx, exec, 1, locationsDuracloud0, locationsSpace1) + if err != nil { + return err + } + + locationsDuracloud0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsDuracloud = locationsDuracloud0 + + return nil +} + +type locationsDuracloudWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Host mysql.WhereMod[Q, string] + User mysql.WhereMod[Q, string] + Password mysql.WhereMod[Q, string] + Duraspace mysql.WhereMod[Q, string] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsDuracloudWhere[Q]) AliasedAs(alias string) locationsDuracloudWhere[Q] { + return buildLocationsDuracloudWhere[Q](buildLocationsDuracloudColumns(alias)) +} + +func buildLocationsDuracloudWhere[Q mysql.Filterable](cols locationsDuracloudColumns) locationsDuracloudWhere[Q] { + return locationsDuracloudWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Host: mysql.Where[Q, string](cols.Host), + User: mysql.Where[Q, string](cols.User), + Password: mysql.Where[Q, string](cols.Password), + Duraspace: mysql.Where[Q, string](cols.Duraspace), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsDuracloud) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsDuracloud cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsDuracloud = o + } + return nil + default: + return fmt.Errorf("locationsDuracloud has no relationship %q", name) + } +} + +type locationsDuracloudPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsDuracloudPreloader() locationsDuracloudPreloader { + return locationsDuracloudPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsDuraclouds, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsDuracloudThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsDuracloudThenLoader[Q orm.Loadable]() locationsDuracloudThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsDuracloudThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsDuracloud's SpaceLocationsSpace into the .R struct +func (o *LocationsDuracloud) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsDuracloud = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsDuracloud's SpaceLocationsSpace into the .R struct +func (os LocationsDuracloudSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsDuracloud = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsDuracloudJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsDuracloudJoins[Q]) aliasedAs(alias string) locationsDuracloudJoins[Q] { + return buildLocationsDuracloudJoins[Q](buildLocationsDuracloudColumns(alias), j.typ) +} + +func buildLocationsDuracloudJoins[Q dialect.Joinable](cols locationsDuracloudColumns, typ string) locationsDuracloudJoins[Q] { + return locationsDuracloudJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_event.bob.go b/database/mcp/models/locations_event.bob.go new file mode 100644 index 0000000..7b2c96a --- /dev/null +++ b/database/mcp/models/locations_event.bob.go @@ -0,0 +1,1180 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsEvent is an object representing the database table. +type LocationsEvent struct { + ID int32 `db:"id,pk,autoincr" ` + EventType string `db:"event_type" ` + EventReason string `db:"event_reason" ` + UserID uint32 `db:"user_id" ` + UserEmail string `db:"user_email" ` + Status string `db:"status" ` + StatusReason null.Val[string] `db:"status_reason" ` + StatusTime time.Time `db:"status_time" ` + StoreData null.Val[string] `db:"store_data" ` + AdminIDID null.Val[int32] `db:"admin_id_id" ` + PackageID string `db:"package_id" ` + PipelineID string `db:"pipeline_id" ` + + R locationsEventR `db:"-" ` +} + +// LocationsEventSlice is an alias for a slice of pointers to LocationsEvent. +// This should almost always be used instead of []*LocationsEvent. +type LocationsEventSlice []*LocationsEvent + +// LocationsEvents contains methods to work with the locations_event table +var LocationsEvents = mysql.NewTablex[*LocationsEvent, LocationsEventSlice, *LocationsEventSetter]("locations_event", buildLocationsEventColumns("locations_event"), []string{"id"}) + +// LocationsEventsQuery is a query on the locations_event table +type LocationsEventsQuery = *mysql.ViewQuery[*LocationsEvent, LocationsEventSlice] + +// locationsEventR is where relationships are stored. +type locationsEventR struct { + AdminIDAuthUser *AuthUser // locations_event_admin_id_id_4a50d36a_fk_auth_user_id + PackageLocationsPackage *LocationsPackage // locations_event_package_id_50db610f_fk_locations_package_uuid + PipelineLocationsPipeline *LocationsPipeline // locations_event_pipeline_id_5188361f_fk_locations_pipeline_uuid +} + +func buildLocationsEventColumns(alias string) locationsEventColumns { + return locationsEventColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "event_type", "event_reason", "user_id", "user_email", "status", "status_reason", "status_time", "store_data", "admin_id_id", "package_id", "pipeline_id", + ).WithParent("locations_event"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + EventType: mysql.Quote(alias, "event_type"), + EventReason: mysql.Quote(alias, "event_reason"), + UserID: mysql.Quote(alias, "user_id"), + UserEmail: mysql.Quote(alias, "user_email"), + Status: mysql.Quote(alias, "status"), + StatusReason: mysql.Quote(alias, "status_reason"), + StatusTime: mysql.Quote(alias, "status_time"), + StoreData: mysql.Quote(alias, "store_data"), + AdminIDID: mysql.Quote(alias, "admin_id_id"), + PackageID: mysql.Quote(alias, "package_id"), + PipelineID: mysql.Quote(alias, "pipeline_id"), + } +} + +type locationsEventColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + EventType mysql.Expression + EventReason mysql.Expression + UserID mysql.Expression + UserEmail mysql.Expression + Status mysql.Expression + StatusReason mysql.Expression + StatusTime mysql.Expression + StoreData mysql.Expression + AdminIDID mysql.Expression + PackageID mysql.Expression + PipelineID mysql.Expression +} + +func (c locationsEventColumns) Alias() string { + return c.tableAlias +} + +func (locationsEventColumns) AliasedAs(alias string) locationsEventColumns { + return buildLocationsEventColumns(alias) +} + +// LocationsEventSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsEventSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + EventType omit.Val[string] `db:"event_type" ` + EventReason omit.Val[string] `db:"event_reason" ` + UserID omit.Val[uint32] `db:"user_id" ` + UserEmail omit.Val[string] `db:"user_email" ` + Status omit.Val[string] `db:"status" ` + StatusReason omitnull.Val[string] `db:"status_reason" ` + StatusTime omit.Val[time.Time] `db:"status_time" ` + StoreData omitnull.Val[string] `db:"store_data" ` + AdminIDID omitnull.Val[int32] `db:"admin_id_id" ` + PackageID omit.Val[string] `db:"package_id" ` + PipelineID omit.Val[string] `db:"pipeline_id" ` +} + +func (s LocationsEventSetter) SetColumns() []string { + vals := make([]string, 0, 12) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.EventType.IsValue() { + vals = append(vals, "event_type") + } + if s.EventReason.IsValue() { + vals = append(vals, "event_reason") + } + if s.UserID.IsValue() { + vals = append(vals, "user_id") + } + if s.UserEmail.IsValue() { + vals = append(vals, "user_email") + } + if s.Status.IsValue() { + vals = append(vals, "status") + } + if !s.StatusReason.IsUnset() { + vals = append(vals, "status_reason") + } + if s.StatusTime.IsValue() { + vals = append(vals, "status_time") + } + if !s.StoreData.IsUnset() { + vals = append(vals, "store_data") + } + if !s.AdminIDID.IsUnset() { + vals = append(vals, "admin_id_id") + } + if s.PackageID.IsValue() { + vals = append(vals, "package_id") + } + if s.PipelineID.IsValue() { + vals = append(vals, "pipeline_id") + } + return vals +} + +func (s LocationsEventSetter) Overwrite(t *LocationsEvent) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.EventType.IsValue() { + t.EventType = s.EventType.MustGet() + } + if s.EventReason.IsValue() { + t.EventReason = s.EventReason.MustGet() + } + if s.UserID.IsValue() { + t.UserID = s.UserID.MustGet() + } + if s.UserEmail.IsValue() { + t.UserEmail = s.UserEmail.MustGet() + } + if s.Status.IsValue() { + t.Status = s.Status.MustGet() + } + if !s.StatusReason.IsUnset() { + t.StatusReason = s.StatusReason.MustGetNull() + } + if s.StatusTime.IsValue() { + t.StatusTime = s.StatusTime.MustGet() + } + if !s.StoreData.IsUnset() { + t.StoreData = s.StoreData.MustGetNull() + } + if !s.AdminIDID.IsUnset() { + t.AdminIDID = s.AdminIDID.MustGetNull() + } + if s.PackageID.IsValue() { + t.PackageID = s.PackageID.MustGet() + } + if s.PipelineID.IsValue() { + t.PipelineID = s.PipelineID.MustGet() + } +} + +func (s *LocationsEventSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsEvents.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.EventType.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.EventType.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.EventReason.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.EventReason.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UserID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UserID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UserEmail.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UserEmail.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Status.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Status.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.StatusReason.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.StatusReason.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.StatusTime.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.StatusTime.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.StoreData.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.StoreData.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.AdminIDID.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AdminIDID.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.PackageID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PackageID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.PipelineID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PipelineID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsEventSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_event")...) +} + +func (s LocationsEventSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 12) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.EventType.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "event_type")...), + mysql.Arg(s.EventType), + }}) + } + + if s.EventReason.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "event_reason")...), + mysql.Arg(s.EventReason), + }}) + } + + if s.UserID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "user_id")...), + mysql.Arg(s.UserID), + }}) + } + + if s.UserEmail.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "user_email")...), + mysql.Arg(s.UserEmail), + }}) + } + + if s.Status.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "status")...), + mysql.Arg(s.Status), + }}) + } + + if !s.StatusReason.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "status_reason")...), + mysql.Arg(s.StatusReason), + }}) + } + + if s.StatusTime.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "status_time")...), + mysql.Arg(s.StatusTime), + }}) + } + + if !s.StoreData.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "store_data")...), + mysql.Arg(s.StoreData), + }}) + } + + if !s.AdminIDID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "admin_id_id")...), + mysql.Arg(s.AdminIDID), + }}) + } + + if s.PackageID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "package_id")...), + mysql.Arg(s.PackageID), + }}) + } + + if s.PipelineID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "pipeline_id")...), + mysql.Arg(s.PipelineID), + }}) + } + + return exprs +} + +// FindLocationsEvent retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsEvent(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsEvent, error) { + if len(cols) == 0 { + return LocationsEvents.Query( + sm.Where(LocationsEvents.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsEvents.Query( + sm.Where(LocationsEvents.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsEvents.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsEventExists checks the presence of a single record by primary key +func LocationsEventExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsEvents.Query( + sm.Where(LocationsEvents.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsEvent is retrieved from the database +func (o *LocationsEvent) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsEvents.AfterSelectHooks.RunHooks(ctx, exec, LocationsEventSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsEvents.AfterInsertHooks.RunHooks(ctx, exec, LocationsEventSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsEvents.AfterUpdateHooks.RunHooks(ctx, exec, LocationsEventSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsEvents.AfterDeleteHooks.RunHooks(ctx, exec, LocationsEventSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsEvent +func (o *LocationsEvent) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsEvent) pkEQ() dialect.Expression { + return mysql.Quote("locations_event", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsEvent +func (o *LocationsEvent) Update(ctx context.Context, exec bob.Executor, s *LocationsEventSetter) error { + _, err := LocationsEvents.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsEvent record with an executor +func (o *LocationsEvent) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsEvents.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsEvent using the executor +func (o *LocationsEvent) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsEvents.Query( + sm.Where(LocationsEvents.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsEventSlice is retrieved from the database +func (o LocationsEventSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsEvents.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsEvents.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsEvents.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsEvents.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsEventSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_event", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsEventSlice) copyMatchingRows(from ...*LocationsEvent) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsEventSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsEvents.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsEvent: + o.copyMatchingRows(retrieved) + case []*LocationsEvent: + o.copyMatchingRows(retrieved...) + case LocationsEventSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsEvent or a slice of LocationsEvent + // then run the AfterUpdateHooks on the slice + _, err = LocationsEvents.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsEventSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsEvents.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsEvent: + o.copyMatchingRows(retrieved) + case []*LocationsEvent: + o.copyMatchingRows(retrieved...) + case LocationsEventSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsEvent or a slice of LocationsEvent + // then run the AfterDeleteHooks on the slice + _, err = LocationsEvents.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsEventSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsEventSetter) error { + _, err := LocationsEvents.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsEventSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsEvents.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsEventSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsEvents.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// AdminIDAuthUser starts a query for related objects on auth_user +func (o *LocationsEvent) AdminIDAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + return AuthUsers.Query(append(mods, + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(o.AdminIDID))), + )...) +} + +func (os LocationsEventSlice) AdminIDAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.AdminIDID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUsers.Query(append(mods, + sm.Where(mysql.Group(AuthUsers.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// PackageLocationsPackage starts a query for related objects on locations_package +func (o *LocationsEvent) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.UUID.EQ(mysql.Arg(o.PackageID))), + )...) +} + +func (os LocationsEventSlice) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PackageID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +// PipelineLocationsPipeline starts a query for related objects on locations_pipeline +func (o *LocationsEvent) PipelineLocationsPipeline(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPipelinesQuery { + return LocationsPipelines.Query(append(mods, + sm.Where(LocationsPipelines.Columns.UUID.EQ(mysql.Arg(o.PipelineID))), + )...) +} + +func (os LocationsEventSlice) PipelineLocationsPipeline(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPipelinesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PipelineID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPipelines.Query(append(mods, + sm.Where(mysql.Group(LocationsPipelines.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsEventAdminIDAuthUser0(ctx context.Context, exec bob.Executor, count int, locationsEvent0 *LocationsEvent, authUser1 *AuthUser) (*LocationsEvent, error) { + setter := &LocationsEventSetter{ + AdminIDID: omitnull.From(authUser1.ID), + } + + err := locationsEvent0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsEventAdminIDAuthUser0: %w", err) + } + + return locationsEvent0, nil +} + +func (locationsEvent0 *LocationsEvent) InsertAdminIDAuthUser(ctx context.Context, exec bob.Executor, related *AuthUserSetter) error { + var err error + + authUser1, err := AuthUsers.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsEventAdminIDAuthUser0(ctx, exec, 1, locationsEvent0, authUser1) + if err != nil { + return err + } + + locationsEvent0.R.AdminIDAuthUser = authUser1 + + authUser1.R.AdminIDLocationsEvents = append(authUser1.R.AdminIDLocationsEvents, locationsEvent0) + + return nil +} + +func (locationsEvent0 *LocationsEvent) AttachAdminIDAuthUser(ctx context.Context, exec bob.Executor, authUser1 *AuthUser) error { + var err error + + _, err = attachLocationsEventAdminIDAuthUser0(ctx, exec, 1, locationsEvent0, authUser1) + if err != nil { + return err + } + + locationsEvent0.R.AdminIDAuthUser = authUser1 + + authUser1.R.AdminIDLocationsEvents = append(authUser1.R.AdminIDLocationsEvents, locationsEvent0) + + return nil +} + +func attachLocationsEventPackageLocationsPackage0(ctx context.Context, exec bob.Executor, count int, locationsEvent0 *LocationsEvent, locationsPackage1 *LocationsPackage) (*LocationsEvent, error) { + setter := &LocationsEventSetter{ + PackageID: omit.From(locationsPackage1.UUID), + } + + err := locationsEvent0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsEventPackageLocationsPackage0: %w", err) + } + + return locationsEvent0, nil +} + +func (locationsEvent0 *LocationsEvent) InsertPackageLocationsPackage(ctx context.Context, exec bob.Executor, related *LocationsPackageSetter) error { + var err error + + locationsPackage1, err := LocationsPackages.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsEventPackageLocationsPackage0(ctx, exec, 1, locationsEvent0, locationsPackage1) + if err != nil { + return err + } + + locationsEvent0.R.PackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.PackageLocationsEvents = append(locationsPackage1.R.PackageLocationsEvents, locationsEvent0) + + return nil +} + +func (locationsEvent0 *LocationsEvent) AttachPackageLocationsPackage(ctx context.Context, exec bob.Executor, locationsPackage1 *LocationsPackage) error { + var err error + + _, err = attachLocationsEventPackageLocationsPackage0(ctx, exec, 1, locationsEvent0, locationsPackage1) + if err != nil { + return err + } + + locationsEvent0.R.PackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.PackageLocationsEvents = append(locationsPackage1.R.PackageLocationsEvents, locationsEvent0) + + return nil +} + +func attachLocationsEventPipelineLocationsPipeline0(ctx context.Context, exec bob.Executor, count int, locationsEvent0 *LocationsEvent, locationsPipeline1 *LocationsPipeline) (*LocationsEvent, error) { + setter := &LocationsEventSetter{ + PipelineID: omit.From(locationsPipeline1.UUID), + } + + err := locationsEvent0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsEventPipelineLocationsPipeline0: %w", err) + } + + return locationsEvent0, nil +} + +func (locationsEvent0 *LocationsEvent) InsertPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, related *LocationsPipelineSetter) error { + var err error + + locationsPipeline1, err := LocationsPipelines.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsEventPipelineLocationsPipeline0(ctx, exec, 1, locationsEvent0, locationsPipeline1) + if err != nil { + return err + } + + locationsEvent0.R.PipelineLocationsPipeline = locationsPipeline1 + + locationsPipeline1.R.PipelineLocationsEvents = append(locationsPipeline1.R.PipelineLocationsEvents, locationsEvent0) + + return nil +} + +func (locationsEvent0 *LocationsEvent) AttachPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, locationsPipeline1 *LocationsPipeline) error { + var err error + + _, err = attachLocationsEventPipelineLocationsPipeline0(ctx, exec, 1, locationsEvent0, locationsPipeline1) + if err != nil { + return err + } + + locationsEvent0.R.PipelineLocationsPipeline = locationsPipeline1 + + locationsPipeline1.R.PipelineLocationsEvents = append(locationsPipeline1.R.PipelineLocationsEvents, locationsEvent0) + + return nil +} + +type locationsEventWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + EventType mysql.WhereMod[Q, string] + EventReason mysql.WhereMod[Q, string] + UserID mysql.WhereMod[Q, uint32] + UserEmail mysql.WhereMod[Q, string] + Status mysql.WhereMod[Q, string] + StatusReason mysql.WhereNullMod[Q, string] + StatusTime mysql.WhereMod[Q, time.Time] + StoreData mysql.WhereNullMod[Q, string] + AdminIDID mysql.WhereNullMod[Q, int32] + PackageID mysql.WhereMod[Q, string] + PipelineID mysql.WhereMod[Q, string] +} + +func (locationsEventWhere[Q]) AliasedAs(alias string) locationsEventWhere[Q] { + return buildLocationsEventWhere[Q](buildLocationsEventColumns(alias)) +} + +func buildLocationsEventWhere[Q mysql.Filterable](cols locationsEventColumns) locationsEventWhere[Q] { + return locationsEventWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + EventType: mysql.Where[Q, string](cols.EventType), + EventReason: mysql.Where[Q, string](cols.EventReason), + UserID: mysql.Where[Q, uint32](cols.UserID), + UserEmail: mysql.Where[Q, string](cols.UserEmail), + Status: mysql.Where[Q, string](cols.Status), + StatusReason: mysql.WhereNull[Q, string](cols.StatusReason), + StatusTime: mysql.Where[Q, time.Time](cols.StatusTime), + StoreData: mysql.WhereNull[Q, string](cols.StoreData), + AdminIDID: mysql.WhereNull[Q, int32](cols.AdminIDID), + PackageID: mysql.Where[Q, string](cols.PackageID), + PipelineID: mysql.Where[Q, string](cols.PipelineID), + } +} + +func (o *LocationsEvent) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "AdminIDAuthUser": + rel, ok := retrieved.(*AuthUser) + if !ok { + return fmt.Errorf("locationsEvent cannot load %T as %q", retrieved, name) + } + + o.R.AdminIDAuthUser = rel + + if rel != nil { + rel.R.AdminIDLocationsEvents = LocationsEventSlice{o} + } + return nil + case "PackageLocationsPackage": + rel, ok := retrieved.(*LocationsPackage) + if !ok { + return fmt.Errorf("locationsEvent cannot load %T as %q", retrieved, name) + } + + o.R.PackageLocationsPackage = rel + + if rel != nil { + rel.R.PackageLocationsEvents = LocationsEventSlice{o} + } + return nil + case "PipelineLocationsPipeline": + rel, ok := retrieved.(*LocationsPipeline) + if !ok { + return fmt.Errorf("locationsEvent cannot load %T as %q", retrieved, name) + } + + o.R.PipelineLocationsPipeline = rel + + if rel != nil { + rel.R.PipelineLocationsEvents = LocationsEventSlice{o} + } + return nil + default: + return fmt.Errorf("locationsEvent has no relationship %q", name) + } +} + +type locationsEventPreloader struct { + AdminIDAuthUser func(...mysql.PreloadOption) mysql.Preloader + PackageLocationsPackage func(...mysql.PreloadOption) mysql.Preloader + PipelineLocationsPipeline func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsEventPreloader() locationsEventPreloader { + return locationsEventPreloader{ + AdminIDAuthUser: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthUser, AuthUserSlice](mysql.PreloadRel{ + Name: "AdminIDAuthUser", + Sides: []mysql.PreloadSide{ + { + From: LocationsEvents, + To: AuthUsers, + FromColumns: []string{"admin_id_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthUsers.Columns.Names(), opts...) + }, + PackageLocationsPackage: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPackage, LocationsPackageSlice](mysql.PreloadRel{ + Name: "PackageLocationsPackage", + Sides: []mysql.PreloadSide{ + { + From: LocationsEvents, + To: LocationsPackages, + FromColumns: []string{"package_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsPackages.Columns.Names(), opts...) + }, + PipelineLocationsPipeline: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPipeline, LocationsPipelineSlice](mysql.PreloadRel{ + Name: "PipelineLocationsPipeline", + Sides: []mysql.PreloadSide{ + { + From: LocationsEvents, + To: LocationsPipelines, + FromColumns: []string{"pipeline_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsPipelines.Columns.Names(), opts...) + }, + } +} + +type locationsEventThenLoader[Q orm.Loadable] struct { + AdminIDAuthUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PackageLocationsPackage func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PipelineLocationsPipeline func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsEventThenLoader[Q orm.Loadable]() locationsEventThenLoader[Q] { + type AdminIDAuthUserLoadInterface interface { + LoadAdminIDAuthUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PackageLocationsPackageLoadInterface interface { + LoadPackageLocationsPackage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PipelineLocationsPipelineLoadInterface interface { + LoadPipelineLocationsPipeline(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsEventThenLoader[Q]{ + AdminIDAuthUser: thenLoadBuilder[Q]( + "AdminIDAuthUser", + func(ctx context.Context, exec bob.Executor, retrieved AdminIDAuthUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadAdminIDAuthUser(ctx, exec, mods...) + }, + ), + PackageLocationsPackage: thenLoadBuilder[Q]( + "PackageLocationsPackage", + func(ctx context.Context, exec bob.Executor, retrieved PackageLocationsPackageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPackageLocationsPackage(ctx, exec, mods...) + }, + ), + PipelineLocationsPipeline: thenLoadBuilder[Q]( + "PipelineLocationsPipeline", + func(ctx context.Context, exec bob.Executor, retrieved PipelineLocationsPipelineLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPipelineLocationsPipeline(ctx, exec, mods...) + }, + ), + } +} + +// LoadAdminIDAuthUser loads the locationsEvent's AdminIDAuthUser into the .R struct +func (o *LocationsEvent) LoadAdminIDAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.AdminIDAuthUser = nil + + related, err := o.AdminIDAuthUser(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.AdminIDLocationsEvents = LocationsEventSlice{o} + + o.R.AdminIDAuthUser = related + return nil +} + +// LoadAdminIDAuthUser loads the locationsEvent's AdminIDAuthUser into the .R struct +func (os LocationsEventSlice) LoadAdminIDAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUsers, err := os.AdminIDAuthUser(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUsers { + if !o.AdminIDID.IsValue() { + continue + } + + if !(o.AdminIDID.IsValue() && o.AdminIDID.MustGet() == rel.ID) { + continue + } + + rel.R.AdminIDLocationsEvents = append(rel.R.AdminIDLocationsEvents, o) + + o.R.AdminIDAuthUser = rel + break + } + } + + return nil +} + +// LoadPackageLocationsPackage loads the locationsEvent's PackageLocationsPackage into the .R struct +func (o *LocationsEvent) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PackageLocationsPackage = nil + + related, err := o.PackageLocationsPackage(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PackageLocationsEvents = LocationsEventSlice{o} + + o.R.PackageLocationsPackage = related + return nil +} + +// LoadPackageLocationsPackage loads the locationsEvent's PackageLocationsPackage into the .R struct +func (os LocationsEventSlice) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.PackageLocationsPackage(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !(o.PackageID == rel.UUID) { + continue + } + + rel.R.PackageLocationsEvents = append(rel.R.PackageLocationsEvents, o) + + o.R.PackageLocationsPackage = rel + break + } + } + + return nil +} + +// LoadPipelineLocationsPipeline loads the locationsEvent's PipelineLocationsPipeline into the .R struct +func (o *LocationsEvent) LoadPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PipelineLocationsPipeline = nil + + related, err := o.PipelineLocationsPipeline(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PipelineLocationsEvents = LocationsEventSlice{o} + + o.R.PipelineLocationsPipeline = related + return nil +} + +// LoadPipelineLocationsPipeline loads the locationsEvent's PipelineLocationsPipeline into the .R struct +func (os LocationsEventSlice) LoadPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPipelines, err := os.PipelineLocationsPipeline(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPipelines { + + if !(o.PipelineID == rel.UUID) { + continue + } + + rel.R.PipelineLocationsEvents = append(rel.R.PipelineLocationsEvents, o) + + o.R.PipelineLocationsPipeline = rel + break + } + } + + return nil +} + +type locationsEventJoins[Q dialect.Joinable] struct { + typ string + AdminIDAuthUser modAs[Q, authUserColumns] + PackageLocationsPackage modAs[Q, locationsPackageColumns] + PipelineLocationsPipeline modAs[Q, locationsPipelineColumns] +} + +func (j locationsEventJoins[Q]) aliasedAs(alias string) locationsEventJoins[Q] { + return buildLocationsEventJoins[Q](buildLocationsEventColumns(alias), j.typ) +} + +func buildLocationsEventJoins[Q dialect.Joinable](cols locationsEventColumns, typ string) locationsEventJoins[Q] { + return locationsEventJoins[Q]{ + typ: typ, + AdminIDAuthUser: modAs[Q, authUserColumns]{ + c: AuthUsers.Columns, + f: func(to authUserColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUsers.Name().As(to.Alias())).On( + to.ID.EQ(cols.AdminIDID), + )) + } + + return mods + }, + }, + PackageLocationsPackage: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.UUID.EQ(cols.PackageID), + )) + } + + return mods + }, + }, + PipelineLocationsPipeline: modAs[Q, locationsPipelineColumns]{ + c: LocationsPipelines.Columns, + f: func(to locationsPipelineColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPipelines.Name().As(to.Alias())).On( + to.UUID.EQ(cols.PipelineID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_fedora.bob.go b/database/mcp/models/locations_fedora.bob.go new file mode 100644 index 0000000..326cdca --- /dev/null +++ b/database/mcp/models/locations_fedora.bob.go @@ -0,0 +1,664 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsFedora is an object representing the database table. +type LocationsFedora struct { + ID int32 `db:"id,pk,autoincr" ` + FedoraUser string `db:"fedora_user" ` + FedoraPassword string `db:"fedora_password" ` + FedoraName string `db:"fedora_name" ` + SpaceID string `db:"space_id" ` + + R locationsFedoraR `db:"-" ` +} + +// LocationsFedoraSlice is an alias for a slice of pointers to LocationsFedora. +// This should almost always be used instead of []*LocationsFedora. +type LocationsFedoraSlice []*LocationsFedora + +// LocationsFedoras contains methods to work with the locations_fedora table +var LocationsFedoras = mysql.NewTablex[*LocationsFedora, LocationsFedoraSlice, *LocationsFedoraSetter]("locations_fedora", buildLocationsFedoraColumns("locations_fedora"), []string{"id"}, []string{"space_id"}) + +// LocationsFedorasQuery is a query on the locations_fedora table +type LocationsFedorasQuery = *mysql.ViewQuery[*LocationsFedora, LocationsFedoraSlice] + +// locationsFedoraR is where relationships are stored. +type locationsFedoraR struct { + SpaceLocationsSpace *LocationsSpace // locations_fedora_space_id_088fe895_fk_locations_space_uuid +} + +func buildLocationsFedoraColumns(alias string) locationsFedoraColumns { + return locationsFedoraColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "fedora_user", "fedora_password", "fedora_name", "space_id", + ).WithParent("locations_fedora"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + FedoraUser: mysql.Quote(alias, "fedora_user"), + FedoraPassword: mysql.Quote(alias, "fedora_password"), + FedoraName: mysql.Quote(alias, "fedora_name"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsFedoraColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + FedoraUser mysql.Expression + FedoraPassword mysql.Expression + FedoraName mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsFedoraColumns) Alias() string { + return c.tableAlias +} + +func (locationsFedoraColumns) AliasedAs(alias string) locationsFedoraColumns { + return buildLocationsFedoraColumns(alias) +} + +// LocationsFedoraSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsFedoraSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + FedoraUser omit.Val[string] `db:"fedora_user" ` + FedoraPassword omit.Val[string] `db:"fedora_password" ` + FedoraName omit.Val[string] `db:"fedora_name" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsFedoraSetter) SetColumns() []string { + vals := make([]string, 0, 5) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.FedoraUser.IsValue() { + vals = append(vals, "fedora_user") + } + if s.FedoraPassword.IsValue() { + vals = append(vals, "fedora_password") + } + if s.FedoraName.IsValue() { + vals = append(vals, "fedora_name") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsFedoraSetter) Overwrite(t *LocationsFedora) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.FedoraUser.IsValue() { + t.FedoraUser = s.FedoraUser.MustGet() + } + if s.FedoraPassword.IsValue() { + t.FedoraPassword = s.FedoraPassword.MustGet() + } + if s.FedoraName.IsValue() { + t.FedoraName = s.FedoraName.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsFedoraSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFedoras.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.FedoraUser.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.FedoraUser.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.FedoraPassword.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.FedoraPassword.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.FedoraName.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.FedoraName.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsFedoraSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_fedora")...) +} + +func (s LocationsFedoraSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 5) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.FedoraUser.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "fedora_user")...), + mysql.Arg(s.FedoraUser), + }}) + } + + if s.FedoraPassword.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "fedora_password")...), + mysql.Arg(s.FedoraPassword), + }}) + } + + if s.FedoraName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "fedora_name")...), + mysql.Arg(s.FedoraName), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsFedora retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsFedora(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsFedora, error) { + if len(cols) == 0 { + return LocationsFedoras.Query( + sm.Where(LocationsFedoras.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsFedoras.Query( + sm.Where(LocationsFedoras.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsFedoras.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsFedoraExists checks the presence of a single record by primary key +func LocationsFedoraExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsFedoras.Query( + sm.Where(LocationsFedoras.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsFedora is retrieved from the database +func (o *LocationsFedora) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsFedoras.AfterSelectHooks.RunHooks(ctx, exec, LocationsFedoraSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsFedoras.AfterInsertHooks.RunHooks(ctx, exec, LocationsFedoraSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsFedoras.AfterUpdateHooks.RunHooks(ctx, exec, LocationsFedoraSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsFedoras.AfterDeleteHooks.RunHooks(ctx, exec, LocationsFedoraSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsFedora +func (o *LocationsFedora) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsFedora) pkEQ() dialect.Expression { + return mysql.Quote("locations_fedora", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsFedora +func (o *LocationsFedora) Update(ctx context.Context, exec bob.Executor, s *LocationsFedoraSetter) error { + _, err := LocationsFedoras.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsFedora record with an executor +func (o *LocationsFedora) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsFedoras.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsFedora using the executor +func (o *LocationsFedora) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsFedoras.Query( + sm.Where(LocationsFedoras.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsFedoraSlice is retrieved from the database +func (o LocationsFedoraSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsFedoras.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsFedoras.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsFedoras.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsFedoras.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsFedoraSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_fedora", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsFedoraSlice) copyMatchingRows(from ...*LocationsFedora) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsFedoraSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFedoras.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsFedora: + o.copyMatchingRows(retrieved) + case []*LocationsFedora: + o.copyMatchingRows(retrieved...) + case LocationsFedoraSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsFedora or a slice of LocationsFedora + // then run the AfterUpdateHooks on the slice + _, err = LocationsFedoras.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsFedoraSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFedoras.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsFedora: + o.copyMatchingRows(retrieved) + case []*LocationsFedora: + o.copyMatchingRows(retrieved...) + case LocationsFedoraSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsFedora or a slice of LocationsFedora + // then run the AfterDeleteHooks on the slice + _, err = LocationsFedoras.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsFedoraSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsFedoraSetter) error { + _, err := LocationsFedoras.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsFedoraSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsFedoras.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsFedoraSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsFedoras.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsFedora) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsFedoraSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsFedoraSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsFedora0 *LocationsFedora, locationsSpace1 *LocationsSpace) (*LocationsFedora, error) { + setter := &LocationsFedoraSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsFedora0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsFedoraSpaceLocationsSpace0: %w", err) + } + + return locationsFedora0, nil +} + +func (locationsFedora0 *LocationsFedora) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsFedoraSpaceLocationsSpace0(ctx, exec, 1, locationsFedora0, locationsSpace1) + if err != nil { + return err + } + + locationsFedora0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsFedora = locationsFedora0 + + return nil +} + +func (locationsFedora0 *LocationsFedora) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsFedoraSpaceLocationsSpace0(ctx, exec, 1, locationsFedora0, locationsSpace1) + if err != nil { + return err + } + + locationsFedora0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsFedora = locationsFedora0 + + return nil +} + +type locationsFedoraWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + FedoraUser mysql.WhereMod[Q, string] + FedoraPassword mysql.WhereMod[Q, string] + FedoraName mysql.WhereMod[Q, string] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsFedoraWhere[Q]) AliasedAs(alias string) locationsFedoraWhere[Q] { + return buildLocationsFedoraWhere[Q](buildLocationsFedoraColumns(alias)) +} + +func buildLocationsFedoraWhere[Q mysql.Filterable](cols locationsFedoraColumns) locationsFedoraWhere[Q] { + return locationsFedoraWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + FedoraUser: mysql.Where[Q, string](cols.FedoraUser), + FedoraPassword: mysql.Where[Q, string](cols.FedoraPassword), + FedoraName: mysql.Where[Q, string](cols.FedoraName), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsFedora) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsFedora cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsFedora = o + } + return nil + default: + return fmt.Errorf("locationsFedora has no relationship %q", name) + } +} + +type locationsFedoraPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsFedoraPreloader() locationsFedoraPreloader { + return locationsFedoraPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsFedoras, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsFedoraThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsFedoraThenLoader[Q orm.Loadable]() locationsFedoraThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsFedoraThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsFedora's SpaceLocationsSpace into the .R struct +func (o *LocationsFedora) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsFedora = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsFedora's SpaceLocationsSpace into the .R struct +func (os LocationsFedoraSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsFedora = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsFedoraJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsFedoraJoins[Q]) aliasedAs(alias string) locationsFedoraJoins[Q] { + return buildLocationsFedoraJoins[Q](buildLocationsFedoraColumns(alias), j.typ) +} + +func buildLocationsFedoraJoins[Q dialect.Joinable](cols locationsFedoraColumns, typ string) locationsFedoraJoins[Q] { + return locationsFedoraJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_file.bob.go b/database/mcp/models/locations_file.bob.go new file mode 100644 index 0000000..a77291a --- /dev/null +++ b/database/mcp/models/locations_file.bob.go @@ -0,0 +1,789 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsFile is an object representing the database table. +type LocationsFile struct { + ID int32 `db:"id,pk,autoincr" ` + UUID string `db:"uuid" ` + Name string `db:"name" ` + SourceID string `db:"source_id" ` + Checksum string `db:"checksum" ` + Stored bool `db:"stored" ` + Accessionid string `db:"accessionid" ` + Origin string `db:"origin" ` + PackageID null.Val[int32] `db:"package_id" ` + SourcePackage string `db:"source_package" ` + + R locationsFileR `db:"-" ` +} + +// LocationsFileSlice is an alias for a slice of pointers to LocationsFile. +// This should almost always be used instead of []*LocationsFile. +type LocationsFileSlice []*LocationsFile + +// LocationsFiles contains methods to work with the locations_file table +var LocationsFiles = mysql.NewTablex[*LocationsFile, LocationsFileSlice, *LocationsFileSetter]("locations_file", buildLocationsFileColumns("locations_file"), []string{"id"}, []string{"uuid"}) + +// LocationsFilesQuery is a query on the locations_file table +type LocationsFilesQuery = *mysql.ViewQuery[*LocationsFile, LocationsFileSlice] + +// locationsFileR is where relationships are stored. +type locationsFileR struct { + PackageLocationsPackage *LocationsPackage // locations_file_package_id_dd478d69_fk_locations_package_id +} + +func buildLocationsFileColumns(alias string) locationsFileColumns { + return locationsFileColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "uuid", "name", "source_id", "checksum", "stored", "accessionid", "origin", "package_id", "source_package", + ).WithParent("locations_file"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UUID: mysql.Quote(alias, "uuid"), + Name: mysql.Quote(alias, "name"), + SourceID: mysql.Quote(alias, "source_id"), + Checksum: mysql.Quote(alias, "checksum"), + Stored: mysql.Quote(alias, "stored"), + Accessionid: mysql.Quote(alias, "accessionid"), + Origin: mysql.Quote(alias, "origin"), + PackageID: mysql.Quote(alias, "package_id"), + SourcePackage: mysql.Quote(alias, "source_package"), + } +} + +type locationsFileColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UUID mysql.Expression + Name mysql.Expression + SourceID mysql.Expression + Checksum mysql.Expression + Stored mysql.Expression + Accessionid mysql.Expression + Origin mysql.Expression + PackageID mysql.Expression + SourcePackage mysql.Expression +} + +func (c locationsFileColumns) Alias() string { + return c.tableAlias +} + +func (locationsFileColumns) AliasedAs(alias string) locationsFileColumns { + return buildLocationsFileColumns(alias) +} + +// LocationsFileSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsFileSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UUID omit.Val[string] `db:"uuid" ` + Name omit.Val[string] `db:"name" ` + SourceID omit.Val[string] `db:"source_id" ` + Checksum omit.Val[string] `db:"checksum" ` + Stored omit.Val[bool] `db:"stored" ` + Accessionid omit.Val[string] `db:"accessionid" ` + Origin omit.Val[string] `db:"origin" ` + PackageID omitnull.Val[int32] `db:"package_id" ` + SourcePackage omit.Val[string] `db:"source_package" ` +} + +func (s LocationsFileSetter) SetColumns() []string { + vals := make([]string, 0, 10) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UUID.IsValue() { + vals = append(vals, "uuid") + } + if s.Name.IsValue() { + vals = append(vals, "name") + } + if s.SourceID.IsValue() { + vals = append(vals, "source_id") + } + if s.Checksum.IsValue() { + vals = append(vals, "checksum") + } + if s.Stored.IsValue() { + vals = append(vals, "stored") + } + if s.Accessionid.IsValue() { + vals = append(vals, "accessionid") + } + if s.Origin.IsValue() { + vals = append(vals, "origin") + } + if !s.PackageID.IsUnset() { + vals = append(vals, "package_id") + } + if s.SourcePackage.IsValue() { + vals = append(vals, "source_package") + } + return vals +} + +func (s LocationsFileSetter) Overwrite(t *LocationsFile) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UUID.IsValue() { + t.UUID = s.UUID.MustGet() + } + if s.Name.IsValue() { + t.Name = s.Name.MustGet() + } + if s.SourceID.IsValue() { + t.SourceID = s.SourceID.MustGet() + } + if s.Checksum.IsValue() { + t.Checksum = s.Checksum.MustGet() + } + if s.Stored.IsValue() { + t.Stored = s.Stored.MustGet() + } + if s.Accessionid.IsValue() { + t.Accessionid = s.Accessionid.MustGet() + } + if s.Origin.IsValue() { + t.Origin = s.Origin.MustGet() + } + if !s.PackageID.IsUnset() { + t.PackageID = s.PackageID.MustGetNull() + } + if s.SourcePackage.IsValue() { + t.SourcePackage = s.SourcePackage.MustGet() + } +} + +func (s *LocationsFileSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFiles.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UUID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UUID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Name.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Name.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SourceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SourceID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Checksum.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Checksum.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Stored.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Stored.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Accessionid.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Accessionid.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Origin.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Origin.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.PackageID.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PackageID.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SourcePackage.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SourcePackage.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsFileSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_file")...) +} + +func (s LocationsFileSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 10) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UUID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uuid")...), + mysql.Arg(s.UUID), + }}) + } + + if s.Name.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "name")...), + mysql.Arg(s.Name), + }}) + } + + if s.SourceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "source_id")...), + mysql.Arg(s.SourceID), + }}) + } + + if s.Checksum.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "checksum")...), + mysql.Arg(s.Checksum), + }}) + } + + if s.Stored.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "stored")...), + mysql.Arg(s.Stored), + }}) + } + + if s.Accessionid.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "accessionid")...), + mysql.Arg(s.Accessionid), + }}) + } + + if s.Origin.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "origin")...), + mysql.Arg(s.Origin), + }}) + } + + if !s.PackageID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "package_id")...), + mysql.Arg(s.PackageID), + }}) + } + + if s.SourcePackage.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "source_package")...), + mysql.Arg(s.SourcePackage), + }}) + } + + return exprs +} + +// FindLocationsFile retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsFile(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsFile, error) { + if len(cols) == 0 { + return LocationsFiles.Query( + sm.Where(LocationsFiles.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsFiles.Query( + sm.Where(LocationsFiles.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsFiles.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsFileExists checks the presence of a single record by primary key +func LocationsFileExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsFiles.Query( + sm.Where(LocationsFiles.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsFile is retrieved from the database +func (o *LocationsFile) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsFiles.AfterSelectHooks.RunHooks(ctx, exec, LocationsFileSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsFiles.AfterInsertHooks.RunHooks(ctx, exec, LocationsFileSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsFiles.AfterUpdateHooks.RunHooks(ctx, exec, LocationsFileSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsFiles.AfterDeleteHooks.RunHooks(ctx, exec, LocationsFileSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsFile +func (o *LocationsFile) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsFile) pkEQ() dialect.Expression { + return mysql.Quote("locations_file", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsFile +func (o *LocationsFile) Update(ctx context.Context, exec bob.Executor, s *LocationsFileSetter) error { + _, err := LocationsFiles.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsFile record with an executor +func (o *LocationsFile) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsFiles.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsFile using the executor +func (o *LocationsFile) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsFiles.Query( + sm.Where(LocationsFiles.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsFileSlice is retrieved from the database +func (o LocationsFileSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsFiles.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsFiles.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsFiles.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsFiles.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsFileSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_file", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsFileSlice) copyMatchingRows(from ...*LocationsFile) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsFileSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFiles.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsFile: + o.copyMatchingRows(retrieved) + case []*LocationsFile: + o.copyMatchingRows(retrieved...) + case LocationsFileSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsFile or a slice of LocationsFile + // then run the AfterUpdateHooks on the slice + _, err = LocationsFiles.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsFileSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFiles.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsFile: + o.copyMatchingRows(retrieved) + case []*LocationsFile: + o.copyMatchingRows(retrieved...) + case LocationsFileSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsFile or a slice of LocationsFile + // then run the AfterDeleteHooks on the slice + _, err = LocationsFiles.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsFileSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsFileSetter) error { + _, err := LocationsFiles.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsFileSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsFiles.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsFileSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsFiles.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// PackageLocationsPackage starts a query for related objects on locations_package +func (o *LocationsFile) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.ID.EQ(mysql.Arg(o.PackageID))), + )...) +} + +func (os LocationsFileSlice) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PackageID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsFilePackageLocationsPackage0(ctx context.Context, exec bob.Executor, count int, locationsFile0 *LocationsFile, locationsPackage1 *LocationsPackage) (*LocationsFile, error) { + setter := &LocationsFileSetter{ + PackageID: omitnull.From(locationsPackage1.ID), + } + + err := locationsFile0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsFilePackageLocationsPackage0: %w", err) + } + + return locationsFile0, nil +} + +func (locationsFile0 *LocationsFile) InsertPackageLocationsPackage(ctx context.Context, exec bob.Executor, related *LocationsPackageSetter) error { + var err error + + locationsPackage1, err := LocationsPackages.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsFilePackageLocationsPackage0(ctx, exec, 1, locationsFile0, locationsPackage1) + if err != nil { + return err + } + + locationsFile0.R.PackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.PackageLocationsFiles = append(locationsPackage1.R.PackageLocationsFiles, locationsFile0) + + return nil +} + +func (locationsFile0 *LocationsFile) AttachPackageLocationsPackage(ctx context.Context, exec bob.Executor, locationsPackage1 *LocationsPackage) error { + var err error + + _, err = attachLocationsFilePackageLocationsPackage0(ctx, exec, 1, locationsFile0, locationsPackage1) + if err != nil { + return err + } + + locationsFile0.R.PackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.PackageLocationsFiles = append(locationsPackage1.R.PackageLocationsFiles, locationsFile0) + + return nil +} + +type locationsFileWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UUID mysql.WhereMod[Q, string] + Name mysql.WhereMod[Q, string] + SourceID mysql.WhereMod[Q, string] + Checksum mysql.WhereMod[Q, string] + Stored mysql.WhereMod[Q, bool] + Accessionid mysql.WhereMod[Q, string] + Origin mysql.WhereMod[Q, string] + PackageID mysql.WhereNullMod[Q, int32] + SourcePackage mysql.WhereMod[Q, string] +} + +func (locationsFileWhere[Q]) AliasedAs(alias string) locationsFileWhere[Q] { + return buildLocationsFileWhere[Q](buildLocationsFileColumns(alias)) +} + +func buildLocationsFileWhere[Q mysql.Filterable](cols locationsFileColumns) locationsFileWhere[Q] { + return locationsFileWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UUID: mysql.Where[Q, string](cols.UUID), + Name: mysql.Where[Q, string](cols.Name), + SourceID: mysql.Where[Q, string](cols.SourceID), + Checksum: mysql.Where[Q, string](cols.Checksum), + Stored: mysql.Where[Q, bool](cols.Stored), + Accessionid: mysql.Where[Q, string](cols.Accessionid), + Origin: mysql.Where[Q, string](cols.Origin), + PackageID: mysql.WhereNull[Q, int32](cols.PackageID), + SourcePackage: mysql.Where[Q, string](cols.SourcePackage), + } +} + +func (o *LocationsFile) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "PackageLocationsPackage": + rel, ok := retrieved.(*LocationsPackage) + if !ok { + return fmt.Errorf("locationsFile cannot load %T as %q", retrieved, name) + } + + o.R.PackageLocationsPackage = rel + + if rel != nil { + rel.R.PackageLocationsFiles = LocationsFileSlice{o} + } + return nil + default: + return fmt.Errorf("locationsFile has no relationship %q", name) + } +} + +type locationsFilePreloader struct { + PackageLocationsPackage func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsFilePreloader() locationsFilePreloader { + return locationsFilePreloader{ + PackageLocationsPackage: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPackage, LocationsPackageSlice](mysql.PreloadRel{ + Name: "PackageLocationsPackage", + Sides: []mysql.PreloadSide{ + { + From: LocationsFiles, + To: LocationsPackages, + FromColumns: []string{"package_id"}, + ToColumns: []string{"id"}, + }, + }, + }, LocationsPackages.Columns.Names(), opts...) + }, + } +} + +type locationsFileThenLoader[Q orm.Loadable] struct { + PackageLocationsPackage func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsFileThenLoader[Q orm.Loadable]() locationsFileThenLoader[Q] { + type PackageLocationsPackageLoadInterface interface { + LoadPackageLocationsPackage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsFileThenLoader[Q]{ + PackageLocationsPackage: thenLoadBuilder[Q]( + "PackageLocationsPackage", + func(ctx context.Context, exec bob.Executor, retrieved PackageLocationsPackageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPackageLocationsPackage(ctx, exec, mods...) + }, + ), + } +} + +// LoadPackageLocationsPackage loads the locationsFile's PackageLocationsPackage into the .R struct +func (o *LocationsFile) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PackageLocationsPackage = nil + + related, err := o.PackageLocationsPackage(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PackageLocationsFiles = LocationsFileSlice{o} + + o.R.PackageLocationsPackage = related + return nil +} + +// LoadPackageLocationsPackage loads the locationsFile's PackageLocationsPackage into the .R struct +func (os LocationsFileSlice) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.PackageLocationsPackage(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + if !o.PackageID.IsValue() { + continue + } + + if !(o.PackageID.IsValue() && o.PackageID.MustGet() == rel.ID) { + continue + } + + rel.R.PackageLocationsFiles = append(rel.R.PackageLocationsFiles, o) + + o.R.PackageLocationsPackage = rel + break + } + } + + return nil +} + +type locationsFileJoins[Q dialect.Joinable] struct { + typ string + PackageLocationsPackage modAs[Q, locationsPackageColumns] +} + +func (j locationsFileJoins[Q]) aliasedAs(alias string) locationsFileJoins[Q] { + return buildLocationsFileJoins[Q](buildLocationsFileColumns(alias), j.typ) +} + +func buildLocationsFileJoins[Q dialect.Joinable](cols locationsFileColumns, typ string) locationsFileJoins[Q] { + return locationsFileJoins[Q]{ + typ: typ, + PackageLocationsPackage: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.ID.EQ(cols.PackageID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_fixitylog.bob.go b/database/mcp/models/locations_fixitylog.bob.go new file mode 100644 index 0000000..4186f9a --- /dev/null +++ b/database/mcp/models/locations_fixitylog.bob.go @@ -0,0 +1,667 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsFixitylog is an object representing the database table. +type LocationsFixitylog struct { + ID int32 `db:"id,pk,autoincr" ` + Success null.Val[bool] `db:"success" ` + ErrorDetails null.Val[string] `db:"error_details" ` + DatetimeReported time.Time `db:"datetime_reported" ` + PackageID string `db:"package_id" ` + + R locationsFixitylogR `db:"-" ` +} + +// LocationsFixitylogSlice is an alias for a slice of pointers to LocationsFixitylog. +// This should almost always be used instead of []*LocationsFixitylog. +type LocationsFixitylogSlice []*LocationsFixitylog + +// LocationsFixitylogs contains methods to work with the locations_fixitylog table +var LocationsFixitylogs = mysql.NewTablex[*LocationsFixitylog, LocationsFixitylogSlice, *LocationsFixitylogSetter]("locations_fixitylog", buildLocationsFixitylogColumns("locations_fixitylog"), []string{"id"}) + +// LocationsFixitylogsQuery is a query on the locations_fixitylog table +type LocationsFixitylogsQuery = *mysql.ViewQuery[*LocationsFixitylog, LocationsFixitylogSlice] + +// locationsFixitylogR is where relationships are stored. +type locationsFixitylogR struct { + PackageLocationsPackage *LocationsPackage // locations_fixitylog_package_id_0201e98f_fk_locations +} + +func buildLocationsFixitylogColumns(alias string) locationsFixitylogColumns { + return locationsFixitylogColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "success", "error_details", "datetime_reported", "package_id", + ).WithParent("locations_fixitylog"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Success: mysql.Quote(alias, "success"), + ErrorDetails: mysql.Quote(alias, "error_details"), + DatetimeReported: mysql.Quote(alias, "datetime_reported"), + PackageID: mysql.Quote(alias, "package_id"), + } +} + +type locationsFixitylogColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Success mysql.Expression + ErrorDetails mysql.Expression + DatetimeReported mysql.Expression + PackageID mysql.Expression +} + +func (c locationsFixitylogColumns) Alias() string { + return c.tableAlias +} + +func (locationsFixitylogColumns) AliasedAs(alias string) locationsFixitylogColumns { + return buildLocationsFixitylogColumns(alias) +} + +// LocationsFixitylogSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsFixitylogSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Success omitnull.Val[bool] `db:"success" ` + ErrorDetails omitnull.Val[string] `db:"error_details" ` + DatetimeReported omit.Val[time.Time] `db:"datetime_reported" ` + PackageID omit.Val[string] `db:"package_id" ` +} + +func (s LocationsFixitylogSetter) SetColumns() []string { + vals := make([]string, 0, 5) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if !s.Success.IsUnset() { + vals = append(vals, "success") + } + if !s.ErrorDetails.IsUnset() { + vals = append(vals, "error_details") + } + if s.DatetimeReported.IsValue() { + vals = append(vals, "datetime_reported") + } + if s.PackageID.IsValue() { + vals = append(vals, "package_id") + } + return vals +} + +func (s LocationsFixitylogSetter) Overwrite(t *LocationsFixitylog) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if !s.Success.IsUnset() { + t.Success = s.Success.MustGetNull() + } + if !s.ErrorDetails.IsUnset() { + t.ErrorDetails = s.ErrorDetails.MustGetNull() + } + if s.DatetimeReported.IsValue() { + t.DatetimeReported = s.DatetimeReported.MustGet() + } + if s.PackageID.IsValue() { + t.PackageID = s.PackageID.MustGet() + } +} + +func (s *LocationsFixitylogSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFixitylogs.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Success.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Success.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.ErrorDetails.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ErrorDetails.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DatetimeReported.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DatetimeReported.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.PackageID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PackageID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsFixitylogSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_fixitylog")...) +} + +func (s LocationsFixitylogSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 5) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if !s.Success.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "success")...), + mysql.Arg(s.Success), + }}) + } + + if !s.ErrorDetails.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "error_details")...), + mysql.Arg(s.ErrorDetails), + }}) + } + + if s.DatetimeReported.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "datetime_reported")...), + mysql.Arg(s.DatetimeReported), + }}) + } + + if s.PackageID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "package_id")...), + mysql.Arg(s.PackageID), + }}) + } + + return exprs +} + +// FindLocationsFixitylog retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsFixitylog(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsFixitylog, error) { + if len(cols) == 0 { + return LocationsFixitylogs.Query( + sm.Where(LocationsFixitylogs.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsFixitylogs.Query( + sm.Where(LocationsFixitylogs.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsFixitylogs.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsFixitylogExists checks the presence of a single record by primary key +func LocationsFixitylogExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsFixitylogs.Query( + sm.Where(LocationsFixitylogs.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsFixitylog is retrieved from the database +func (o *LocationsFixitylog) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsFixitylogs.AfterSelectHooks.RunHooks(ctx, exec, LocationsFixitylogSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsFixitylogs.AfterInsertHooks.RunHooks(ctx, exec, LocationsFixitylogSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsFixitylogs.AfterUpdateHooks.RunHooks(ctx, exec, LocationsFixitylogSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsFixitylogs.AfterDeleteHooks.RunHooks(ctx, exec, LocationsFixitylogSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsFixitylog +func (o *LocationsFixitylog) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsFixitylog) pkEQ() dialect.Expression { + return mysql.Quote("locations_fixitylog", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsFixitylog +func (o *LocationsFixitylog) Update(ctx context.Context, exec bob.Executor, s *LocationsFixitylogSetter) error { + _, err := LocationsFixitylogs.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsFixitylog record with an executor +func (o *LocationsFixitylog) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsFixitylogs.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsFixitylog using the executor +func (o *LocationsFixitylog) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsFixitylogs.Query( + sm.Where(LocationsFixitylogs.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsFixitylogSlice is retrieved from the database +func (o LocationsFixitylogSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsFixitylogs.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsFixitylogs.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsFixitylogs.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsFixitylogs.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsFixitylogSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_fixitylog", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsFixitylogSlice) copyMatchingRows(from ...*LocationsFixitylog) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsFixitylogSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFixitylogs.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsFixitylog: + o.copyMatchingRows(retrieved) + case []*LocationsFixitylog: + o.copyMatchingRows(retrieved...) + case LocationsFixitylogSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsFixitylog or a slice of LocationsFixitylog + // then run the AfterUpdateHooks on the slice + _, err = LocationsFixitylogs.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsFixitylogSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFixitylogs.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsFixitylog: + o.copyMatchingRows(retrieved) + case []*LocationsFixitylog: + o.copyMatchingRows(retrieved...) + case LocationsFixitylogSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsFixitylog or a slice of LocationsFixitylog + // then run the AfterDeleteHooks on the slice + _, err = LocationsFixitylogs.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsFixitylogSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsFixitylogSetter) error { + _, err := LocationsFixitylogs.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsFixitylogSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsFixitylogs.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsFixitylogSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsFixitylogs.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// PackageLocationsPackage starts a query for related objects on locations_package +func (o *LocationsFixitylog) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.UUID.EQ(mysql.Arg(o.PackageID))), + )...) +} + +func (os LocationsFixitylogSlice) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PackageID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsFixitylogPackageLocationsPackage0(ctx context.Context, exec bob.Executor, count int, locationsFixitylog0 *LocationsFixitylog, locationsPackage1 *LocationsPackage) (*LocationsFixitylog, error) { + setter := &LocationsFixitylogSetter{ + PackageID: omit.From(locationsPackage1.UUID), + } + + err := locationsFixitylog0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsFixitylogPackageLocationsPackage0: %w", err) + } + + return locationsFixitylog0, nil +} + +func (locationsFixitylog0 *LocationsFixitylog) InsertPackageLocationsPackage(ctx context.Context, exec bob.Executor, related *LocationsPackageSetter) error { + var err error + + locationsPackage1, err := LocationsPackages.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsFixitylogPackageLocationsPackage0(ctx, exec, 1, locationsFixitylog0, locationsPackage1) + if err != nil { + return err + } + + locationsFixitylog0.R.PackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.PackageLocationsFixitylogs = append(locationsPackage1.R.PackageLocationsFixitylogs, locationsFixitylog0) + + return nil +} + +func (locationsFixitylog0 *LocationsFixitylog) AttachPackageLocationsPackage(ctx context.Context, exec bob.Executor, locationsPackage1 *LocationsPackage) error { + var err error + + _, err = attachLocationsFixitylogPackageLocationsPackage0(ctx, exec, 1, locationsFixitylog0, locationsPackage1) + if err != nil { + return err + } + + locationsFixitylog0.R.PackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.PackageLocationsFixitylogs = append(locationsPackage1.R.PackageLocationsFixitylogs, locationsFixitylog0) + + return nil +} + +type locationsFixitylogWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Success mysql.WhereNullMod[Q, bool] + ErrorDetails mysql.WhereNullMod[Q, string] + DatetimeReported mysql.WhereMod[Q, time.Time] + PackageID mysql.WhereMod[Q, string] +} + +func (locationsFixitylogWhere[Q]) AliasedAs(alias string) locationsFixitylogWhere[Q] { + return buildLocationsFixitylogWhere[Q](buildLocationsFixitylogColumns(alias)) +} + +func buildLocationsFixitylogWhere[Q mysql.Filterable](cols locationsFixitylogColumns) locationsFixitylogWhere[Q] { + return locationsFixitylogWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Success: mysql.WhereNull[Q, bool](cols.Success), + ErrorDetails: mysql.WhereNull[Q, string](cols.ErrorDetails), + DatetimeReported: mysql.Where[Q, time.Time](cols.DatetimeReported), + PackageID: mysql.Where[Q, string](cols.PackageID), + } +} + +func (o *LocationsFixitylog) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "PackageLocationsPackage": + rel, ok := retrieved.(*LocationsPackage) + if !ok { + return fmt.Errorf("locationsFixitylog cannot load %T as %q", retrieved, name) + } + + o.R.PackageLocationsPackage = rel + + if rel != nil { + rel.R.PackageLocationsFixitylogs = LocationsFixitylogSlice{o} + } + return nil + default: + return fmt.Errorf("locationsFixitylog has no relationship %q", name) + } +} + +type locationsFixitylogPreloader struct { + PackageLocationsPackage func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsFixitylogPreloader() locationsFixitylogPreloader { + return locationsFixitylogPreloader{ + PackageLocationsPackage: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPackage, LocationsPackageSlice](mysql.PreloadRel{ + Name: "PackageLocationsPackage", + Sides: []mysql.PreloadSide{ + { + From: LocationsFixitylogs, + To: LocationsPackages, + FromColumns: []string{"package_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsPackages.Columns.Names(), opts...) + }, + } +} + +type locationsFixitylogThenLoader[Q orm.Loadable] struct { + PackageLocationsPackage func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsFixitylogThenLoader[Q orm.Loadable]() locationsFixitylogThenLoader[Q] { + type PackageLocationsPackageLoadInterface interface { + LoadPackageLocationsPackage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsFixitylogThenLoader[Q]{ + PackageLocationsPackage: thenLoadBuilder[Q]( + "PackageLocationsPackage", + func(ctx context.Context, exec bob.Executor, retrieved PackageLocationsPackageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPackageLocationsPackage(ctx, exec, mods...) + }, + ), + } +} + +// LoadPackageLocationsPackage loads the locationsFixitylog's PackageLocationsPackage into the .R struct +func (o *LocationsFixitylog) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PackageLocationsPackage = nil + + related, err := o.PackageLocationsPackage(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PackageLocationsFixitylogs = LocationsFixitylogSlice{o} + + o.R.PackageLocationsPackage = related + return nil +} + +// LoadPackageLocationsPackage loads the locationsFixitylog's PackageLocationsPackage into the .R struct +func (os LocationsFixitylogSlice) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.PackageLocationsPackage(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !(o.PackageID == rel.UUID) { + continue + } + + rel.R.PackageLocationsFixitylogs = append(rel.R.PackageLocationsFixitylogs, o) + + o.R.PackageLocationsPackage = rel + break + } + } + + return nil +} + +type locationsFixitylogJoins[Q dialect.Joinable] struct { + typ string + PackageLocationsPackage modAs[Q, locationsPackageColumns] +} + +func (j locationsFixitylogJoins[Q]) aliasedAs(alias string) locationsFixitylogJoins[Q] { + return buildLocationsFixitylogJoins[Q](buildLocationsFixitylogColumns(alias), j.typ) +} + +func buildLocationsFixitylogJoins[Q dialect.Joinable](cols locationsFixitylogColumns, typ string) locationsFixitylogJoins[Q] { + return locationsFixitylogJoins[Q]{ + typ: typ, + PackageLocationsPackage: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.UUID.EQ(cols.PackageID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_gpg.bob.go b/database/mcp/models/locations_gpg.bob.go new file mode 100644 index 0000000..1daeeb0 --- /dev/null +++ b/database/mcp/models/locations_gpg.bob.go @@ -0,0 +1,616 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsGPG is an object representing the database table. +type LocationsGPG struct { + ID int32 `db:"id,pk,autoincr" ` + SpaceID string `db:"space_id" ` + Key string `db:"key" ` + + R locationsGPGR `db:"-" ` +} + +// LocationsGPGSlice is an alias for a slice of pointers to LocationsGPG. +// This should almost always be used instead of []*LocationsGPG. +type LocationsGPGSlice []*LocationsGPG + +// LocationsGPGS contains methods to work with the locations_gpg table +var LocationsGPGS = mysql.NewTablex[*LocationsGPG, LocationsGPGSlice, *LocationsGPGSetter]("locations_gpg", buildLocationsGPGColumns("locations_gpg"), []string{"id"}, []string{"space_id"}) + +// LocationsGPGSQuery is a query on the locations_gpg table +type LocationsGPGSQuery = *mysql.ViewQuery[*LocationsGPG, LocationsGPGSlice] + +// locationsGPGR is where relationships are stored. +type locationsGPGR struct { + SpaceLocationsSpace *LocationsSpace // locations_gpg_space_id_6223440d_fk_locations_space_uuid +} + +func buildLocationsGPGColumns(alias string) locationsGPGColumns { + return locationsGPGColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "space_id", "key", + ).WithParent("locations_gpg"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + SpaceID: mysql.Quote(alias, "space_id"), + Key: mysql.Quote(alias, "key"), + } +} + +type locationsGPGColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + SpaceID mysql.Expression + Key mysql.Expression +} + +func (c locationsGPGColumns) Alias() string { + return c.tableAlias +} + +func (locationsGPGColumns) AliasedAs(alias string) locationsGPGColumns { + return buildLocationsGPGColumns(alias) +} + +// LocationsGPGSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsGPGSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + SpaceID omit.Val[string] `db:"space_id" ` + Key omit.Val[string] `db:"key" ` +} + +func (s LocationsGPGSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + if s.Key.IsValue() { + vals = append(vals, "key") + } + return vals +} + +func (s LocationsGPGSetter) Overwrite(t *LocationsGPG) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } + if s.Key.IsValue() { + t.Key = s.Key.MustGet() + } +} + +func (s *LocationsGPGSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsGPGS.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Key.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Key.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsGPGSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_gpg")...) +} + +func (s LocationsGPGSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + if s.Key.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "key")...), + mysql.Arg(s.Key), + }}) + } + + return exprs +} + +// FindLocationsGPG retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsGPG(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsGPG, error) { + if len(cols) == 0 { + return LocationsGPGS.Query( + sm.Where(LocationsGPGS.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsGPGS.Query( + sm.Where(LocationsGPGS.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsGPGS.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsGPGExists checks the presence of a single record by primary key +func LocationsGPGExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsGPGS.Query( + sm.Where(LocationsGPGS.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsGPG is retrieved from the database +func (o *LocationsGPG) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsGPGS.AfterSelectHooks.RunHooks(ctx, exec, LocationsGPGSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsGPGS.AfterInsertHooks.RunHooks(ctx, exec, LocationsGPGSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsGPGS.AfterUpdateHooks.RunHooks(ctx, exec, LocationsGPGSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsGPGS.AfterDeleteHooks.RunHooks(ctx, exec, LocationsGPGSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsGPG +func (o *LocationsGPG) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsGPG) pkEQ() dialect.Expression { + return mysql.Quote("locations_gpg", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsGPG +func (o *LocationsGPG) Update(ctx context.Context, exec bob.Executor, s *LocationsGPGSetter) error { + _, err := LocationsGPGS.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsGPG record with an executor +func (o *LocationsGPG) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsGPGS.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsGPG using the executor +func (o *LocationsGPG) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsGPGS.Query( + sm.Where(LocationsGPGS.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsGPGSlice is retrieved from the database +func (o LocationsGPGSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsGPGS.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsGPGS.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsGPGS.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsGPGS.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsGPGSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_gpg", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsGPGSlice) copyMatchingRows(from ...*LocationsGPG) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsGPGSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsGPGS.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsGPG: + o.copyMatchingRows(retrieved) + case []*LocationsGPG: + o.copyMatchingRows(retrieved...) + case LocationsGPGSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsGPG or a slice of LocationsGPG + // then run the AfterUpdateHooks on the slice + _, err = LocationsGPGS.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsGPGSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsGPGS.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsGPG: + o.copyMatchingRows(retrieved) + case []*LocationsGPG: + o.copyMatchingRows(retrieved...) + case LocationsGPGSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsGPG or a slice of LocationsGPG + // then run the AfterDeleteHooks on the slice + _, err = LocationsGPGS.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsGPGSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsGPGSetter) error { + _, err := LocationsGPGS.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsGPGSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsGPGS.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsGPGSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsGPGS.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsGPG) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsGPGSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsGPGSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsGPG0 *LocationsGPG, locationsSpace1 *LocationsSpace) (*LocationsGPG, error) { + setter := &LocationsGPGSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsGPG0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsGPGSpaceLocationsSpace0: %w", err) + } + + return locationsGPG0, nil +} + +func (locationsGPG0 *LocationsGPG) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsGPGSpaceLocationsSpace0(ctx, exec, 1, locationsGPG0, locationsSpace1) + if err != nil { + return err + } + + locationsGPG0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsGPG = locationsGPG0 + + return nil +} + +func (locationsGPG0 *LocationsGPG) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsGPGSpaceLocationsSpace0(ctx, exec, 1, locationsGPG0, locationsSpace1) + if err != nil { + return err + } + + locationsGPG0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsGPG = locationsGPG0 + + return nil +} + +type locationsGPGWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + SpaceID mysql.WhereMod[Q, string] + Key mysql.WhereMod[Q, string] +} + +func (locationsGPGWhere[Q]) AliasedAs(alias string) locationsGPGWhere[Q] { + return buildLocationsGPGWhere[Q](buildLocationsGPGColumns(alias)) +} + +func buildLocationsGPGWhere[Q mysql.Filterable](cols locationsGPGColumns) locationsGPGWhere[Q] { + return locationsGPGWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + Key: mysql.Where[Q, string](cols.Key), + } +} + +func (o *LocationsGPG) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsGPG cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsGPG = o + } + return nil + default: + return fmt.Errorf("locationsGPG has no relationship %q", name) + } +} + +type locationsGPGPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsGPGPreloader() locationsGPGPreloader { + return locationsGPGPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsGPGS, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsGPGThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsGPGThenLoader[Q orm.Loadable]() locationsGPGThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsGPGThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsGPG's SpaceLocationsSpace into the .R struct +func (o *LocationsGPG) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsGPG = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsGPG's SpaceLocationsSpace into the .R struct +func (os LocationsGPGSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsGPG = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsGPGJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsGPGJoins[Q]) aliasedAs(alias string) locationsGPGJoins[Q] { + return buildLocationsGPGJoins[Q](buildLocationsGPGColumns(alias), j.typ) +} + +func buildLocationsGPGJoins[Q dialect.Joinable](cols locationsGPGColumns, typ string) locationsGPGJoins[Q] { + return locationsGPGJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_localfilesystem.bob.go b/database/mcp/models/locations_localfilesystem.bob.go new file mode 100644 index 0000000..7d2c2fc --- /dev/null +++ b/database/mcp/models/locations_localfilesystem.bob.go @@ -0,0 +1,592 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsLocalfilesystem is an object representing the database table. +type LocationsLocalfilesystem struct { + ID int32 `db:"id,pk,autoincr" ` + SpaceID string `db:"space_id" ` + + R locationsLocalfilesystemR `db:"-" ` +} + +// LocationsLocalfilesystemSlice is an alias for a slice of pointers to LocationsLocalfilesystem. +// This should almost always be used instead of []*LocationsLocalfilesystem. +type LocationsLocalfilesystemSlice []*LocationsLocalfilesystem + +// LocationsLocalfilesystems contains methods to work with the locations_localfilesystem table +var LocationsLocalfilesystems = mysql.NewTablex[*LocationsLocalfilesystem, LocationsLocalfilesystemSlice, *LocationsLocalfilesystemSetter]("locations_localfilesystem", buildLocationsLocalfilesystemColumns("locations_localfilesystem"), []string{"id"}, []string{"space_id"}) + +// LocationsLocalfilesystemsQuery is a query on the locations_localfilesystem table +type LocationsLocalfilesystemsQuery = *mysql.ViewQuery[*LocationsLocalfilesystem, LocationsLocalfilesystemSlice] + +// locationsLocalfilesystemR is where relationships are stored. +type locationsLocalfilesystemR struct { + SpaceLocationsSpace *LocationsSpace // locations_localfiles_space_id_a97d3d9f_fk_locations +} + +func buildLocationsLocalfilesystemColumns(alias string) locationsLocalfilesystemColumns { + return locationsLocalfilesystemColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "space_id", + ).WithParent("locations_localfilesystem"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsLocalfilesystemColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsLocalfilesystemColumns) Alias() string { + return c.tableAlias +} + +func (locationsLocalfilesystemColumns) AliasedAs(alias string) locationsLocalfilesystemColumns { + return buildLocationsLocalfilesystemColumns(alias) +} + +// LocationsLocalfilesystemSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsLocalfilesystemSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsLocalfilesystemSetter) SetColumns() []string { + vals := make([]string, 0, 2) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsLocalfilesystemSetter) Overwrite(t *LocationsLocalfilesystem) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsLocalfilesystemSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocalfilesystems.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsLocalfilesystemSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_localfilesystem")...) +} + +func (s LocationsLocalfilesystemSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 2) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsLocalfilesystem retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsLocalfilesystem(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsLocalfilesystem, error) { + if len(cols) == 0 { + return LocationsLocalfilesystems.Query( + sm.Where(LocationsLocalfilesystems.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsLocalfilesystems.Query( + sm.Where(LocationsLocalfilesystems.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsLocalfilesystems.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsLocalfilesystemExists checks the presence of a single record by primary key +func LocationsLocalfilesystemExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsLocalfilesystems.Query( + sm.Where(LocationsLocalfilesystems.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsLocalfilesystem is retrieved from the database +func (o *LocationsLocalfilesystem) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLocalfilesystems.AfterSelectHooks.RunHooks(ctx, exec, LocationsLocalfilesystemSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsLocalfilesystems.AfterInsertHooks.RunHooks(ctx, exec, LocationsLocalfilesystemSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsLocalfilesystems.AfterUpdateHooks.RunHooks(ctx, exec, LocationsLocalfilesystemSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsLocalfilesystems.AfterDeleteHooks.RunHooks(ctx, exec, LocationsLocalfilesystemSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsLocalfilesystem +func (o *LocationsLocalfilesystem) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsLocalfilesystem) pkEQ() dialect.Expression { + return mysql.Quote("locations_localfilesystem", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsLocalfilesystem +func (o *LocationsLocalfilesystem) Update(ctx context.Context, exec bob.Executor, s *LocationsLocalfilesystemSetter) error { + _, err := LocationsLocalfilesystems.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsLocalfilesystem record with an executor +func (o *LocationsLocalfilesystem) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsLocalfilesystems.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsLocalfilesystem using the executor +func (o *LocationsLocalfilesystem) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsLocalfilesystems.Query( + sm.Where(LocationsLocalfilesystems.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsLocalfilesystemSlice is retrieved from the database +func (o LocationsLocalfilesystemSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLocalfilesystems.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsLocalfilesystems.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsLocalfilesystems.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsLocalfilesystems.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsLocalfilesystemSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_localfilesystem", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsLocalfilesystemSlice) copyMatchingRows(from ...*LocationsLocalfilesystem) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsLocalfilesystemSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocalfilesystems.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLocalfilesystem: + o.copyMatchingRows(retrieved) + case []*LocationsLocalfilesystem: + o.copyMatchingRows(retrieved...) + case LocationsLocalfilesystemSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLocalfilesystem or a slice of LocationsLocalfilesystem + // then run the AfterUpdateHooks on the slice + _, err = LocationsLocalfilesystems.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsLocalfilesystemSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocalfilesystems.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLocalfilesystem: + o.copyMatchingRows(retrieved) + case []*LocationsLocalfilesystem: + o.copyMatchingRows(retrieved...) + case LocationsLocalfilesystemSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLocalfilesystem or a slice of LocationsLocalfilesystem + // then run the AfterDeleteHooks on the slice + _, err = LocationsLocalfilesystems.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsLocalfilesystemSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsLocalfilesystemSetter) error { + _, err := LocationsLocalfilesystems.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsLocalfilesystemSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsLocalfilesystems.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsLocalfilesystemSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsLocalfilesystems.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsLocalfilesystem) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsLocalfilesystemSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsLocalfilesystemSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsLocalfilesystem0 *LocationsLocalfilesystem, locationsSpace1 *LocationsSpace) (*LocationsLocalfilesystem, error) { + setter := &LocationsLocalfilesystemSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsLocalfilesystem0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocalfilesystemSpaceLocationsSpace0: %w", err) + } + + return locationsLocalfilesystem0, nil +} + +func (locationsLocalfilesystem0 *LocationsLocalfilesystem) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsLocalfilesystemSpaceLocationsSpace0(ctx, exec, 1, locationsLocalfilesystem0, locationsSpace1) + if err != nil { + return err + } + + locationsLocalfilesystem0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsLocalfilesystem = locationsLocalfilesystem0 + + return nil +} + +func (locationsLocalfilesystem0 *LocationsLocalfilesystem) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsLocalfilesystemSpaceLocationsSpace0(ctx, exec, 1, locationsLocalfilesystem0, locationsSpace1) + if err != nil { + return err + } + + locationsLocalfilesystem0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsLocalfilesystem = locationsLocalfilesystem0 + + return nil +} + +type locationsLocalfilesystemWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsLocalfilesystemWhere[Q]) AliasedAs(alias string) locationsLocalfilesystemWhere[Q] { + return buildLocationsLocalfilesystemWhere[Q](buildLocationsLocalfilesystemColumns(alias)) +} + +func buildLocationsLocalfilesystemWhere[Q mysql.Filterable](cols locationsLocalfilesystemColumns) locationsLocalfilesystemWhere[Q] { + return locationsLocalfilesystemWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsLocalfilesystem) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsLocalfilesystem cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsLocalfilesystem = o + } + return nil + default: + return fmt.Errorf("locationsLocalfilesystem has no relationship %q", name) + } +} + +type locationsLocalfilesystemPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsLocalfilesystemPreloader() locationsLocalfilesystemPreloader { + return locationsLocalfilesystemPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsLocalfilesystems, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsLocalfilesystemThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsLocalfilesystemThenLoader[Q orm.Loadable]() locationsLocalfilesystemThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsLocalfilesystemThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsLocalfilesystem's SpaceLocationsSpace into the .R struct +func (o *LocationsLocalfilesystem) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsLocalfilesystem = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsLocalfilesystem's SpaceLocationsSpace into the .R struct +func (os LocationsLocalfilesystemSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsLocalfilesystem = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsLocalfilesystemJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsLocalfilesystemJoins[Q]) aliasedAs(alias string) locationsLocalfilesystemJoins[Q] { + return buildLocationsLocalfilesystemJoins[Q](buildLocationsLocalfilesystemColumns(alias), j.typ) +} + +func buildLocationsLocalfilesystemJoins[Q dialect.Joinable](cols locationsLocalfilesystemColumns, typ string) locationsLocalfilesystemJoins[Q] { + return locationsLocalfilesystemJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_location.bob.go b/database/mcp/models/locations_location.bob.go new file mode 100644 index 0000000..bc6fb21 --- /dev/null +++ b/database/mcp/models/locations_location.bob.go @@ -0,0 +1,1705 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsLocation is an object representing the database table. +type LocationsLocation struct { + ID int32 `db:"id,pk,autoincr" ` + UUID string `db:"uuid" ` + Purpose string `db:"purpose" ` + RelativePath string `db:"relative_path" ` + Description null.Val[string] `db:"description" ` + Quota null.Val[int64] `db:"quota" ` + Used int64 `db:"used" ` + Enabled bool `db:"enabled" ` + SpaceID string `db:"space_id" ` + + R locationsLocationR `db:"-" ` +} + +// LocationsLocationSlice is an alias for a slice of pointers to LocationsLocation. +// This should almost always be used instead of []*LocationsLocation. +type LocationsLocationSlice []*LocationsLocation + +// LocationsLocations contains methods to work with the locations_location table +var LocationsLocations = mysql.NewTablex[*LocationsLocation, LocationsLocationSlice, *LocationsLocationSetter]("locations_location", buildLocationsLocationColumns("locations_location"), []string{"id"}, []string{"uuid"}) + +// LocationsLocationsQuery is a query on the locations_location table +type LocationsLocationsQuery = *mysql.ViewQuery[*LocationsLocation, LocationsLocationSlice] + +// locationsLocationR is where relationships are stored. +type locationsLocationR struct { + FromLocationLocationsLocationReplicators LocationsLocationReplicatorSlice // locations_location_r_from_location_id_3b9a55f5_fk_locations + ToLocationLocationsLocationReplicators LocationsLocationReplicatorSlice // locations_location_r_to_location_id_27be9af1_fk_locations + SpaceLocationsSpace *LocationsSpace // locations_location_space_id_748845a7_fk_locations_space_uuid + LocationLocationsLocationpipelines LocationsLocationpipelineSlice // locations_locationpi_location_id_1bff2f57_fk_locations + CurrentLocationLocationsPackages LocationsPackageSlice // locations_package_current_location_id_c8f7daee_fk_locations + PointerFileLocationLocationsPackages LocationsPackageSlice // locations_package_pointer_file_locatio_2adf5d3c_fk_locations +} + +func buildLocationsLocationColumns(alias string) locationsLocationColumns { + return locationsLocationColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "uuid", "purpose", "relative_path", "description", "quota", "used", "enabled", "space_id", + ).WithParent("locations_location"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UUID: mysql.Quote(alias, "uuid"), + Purpose: mysql.Quote(alias, "purpose"), + RelativePath: mysql.Quote(alias, "relative_path"), + Description: mysql.Quote(alias, "description"), + Quota: mysql.Quote(alias, "quota"), + Used: mysql.Quote(alias, "used"), + Enabled: mysql.Quote(alias, "enabled"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsLocationColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UUID mysql.Expression + Purpose mysql.Expression + RelativePath mysql.Expression + Description mysql.Expression + Quota mysql.Expression + Used mysql.Expression + Enabled mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsLocationColumns) Alias() string { + return c.tableAlias +} + +func (locationsLocationColumns) AliasedAs(alias string) locationsLocationColumns { + return buildLocationsLocationColumns(alias) +} + +// LocationsLocationSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsLocationSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UUID omit.Val[string] `db:"uuid" ` + Purpose omit.Val[string] `db:"purpose" ` + RelativePath omit.Val[string] `db:"relative_path" ` + Description omitnull.Val[string] `db:"description" ` + Quota omitnull.Val[int64] `db:"quota" ` + Used omit.Val[int64] `db:"used" ` + Enabled omit.Val[bool] `db:"enabled" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsLocationSetter) SetColumns() []string { + vals := make([]string, 0, 9) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UUID.IsValue() { + vals = append(vals, "uuid") + } + if s.Purpose.IsValue() { + vals = append(vals, "purpose") + } + if s.RelativePath.IsValue() { + vals = append(vals, "relative_path") + } + if !s.Description.IsUnset() { + vals = append(vals, "description") + } + if !s.Quota.IsUnset() { + vals = append(vals, "quota") + } + if s.Used.IsValue() { + vals = append(vals, "used") + } + if s.Enabled.IsValue() { + vals = append(vals, "enabled") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsLocationSetter) Overwrite(t *LocationsLocation) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UUID.IsValue() { + t.UUID = s.UUID.MustGet() + } + if s.Purpose.IsValue() { + t.Purpose = s.Purpose.MustGet() + } + if s.RelativePath.IsValue() { + t.RelativePath = s.RelativePath.MustGet() + } + if !s.Description.IsUnset() { + t.Description = s.Description.MustGetNull() + } + if !s.Quota.IsUnset() { + t.Quota = s.Quota.MustGetNull() + } + if s.Used.IsValue() { + t.Used = s.Used.MustGet() + } + if s.Enabled.IsValue() { + t.Enabled = s.Enabled.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsLocationSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocations.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UUID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UUID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Purpose.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Purpose.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.RelativePath.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RelativePath.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Description.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Description.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Quota.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Quota.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Used.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Used.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Enabled.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Enabled.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsLocationSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_location")...) +} + +func (s LocationsLocationSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 9) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UUID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uuid")...), + mysql.Arg(s.UUID), + }}) + } + + if s.Purpose.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "purpose")...), + mysql.Arg(s.Purpose), + }}) + } + + if s.RelativePath.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "relative_path")...), + mysql.Arg(s.RelativePath), + }}) + } + + if !s.Description.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "description")...), + mysql.Arg(s.Description), + }}) + } + + if !s.Quota.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "quota")...), + mysql.Arg(s.Quota), + }}) + } + + if s.Used.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "used")...), + mysql.Arg(s.Used), + }}) + } + + if s.Enabled.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "enabled")...), + mysql.Arg(s.Enabled), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsLocation retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsLocation(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsLocation, error) { + if len(cols) == 0 { + return LocationsLocations.Query( + sm.Where(LocationsLocations.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsLocations.Query( + sm.Where(LocationsLocations.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsLocations.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsLocationExists checks the presence of a single record by primary key +func LocationsLocationExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsLocations.Query( + sm.Where(LocationsLocations.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsLocation is retrieved from the database +func (o *LocationsLocation) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLocations.AfterSelectHooks.RunHooks(ctx, exec, LocationsLocationSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsLocations.AfterInsertHooks.RunHooks(ctx, exec, LocationsLocationSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsLocations.AfterUpdateHooks.RunHooks(ctx, exec, LocationsLocationSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsLocations.AfterDeleteHooks.RunHooks(ctx, exec, LocationsLocationSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsLocation +func (o *LocationsLocation) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsLocation) pkEQ() dialect.Expression { + return mysql.Quote("locations_location", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsLocation +func (o *LocationsLocation) Update(ctx context.Context, exec bob.Executor, s *LocationsLocationSetter) error { + _, err := LocationsLocations.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsLocation record with an executor +func (o *LocationsLocation) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsLocations.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsLocation using the executor +func (o *LocationsLocation) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsLocations.Query( + sm.Where(LocationsLocations.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsLocationSlice is retrieved from the database +func (o LocationsLocationSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLocations.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsLocations.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsLocations.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsLocations.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsLocationSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_location", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsLocationSlice) copyMatchingRows(from ...*LocationsLocation) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsLocationSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocations.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLocation: + o.copyMatchingRows(retrieved) + case []*LocationsLocation: + o.copyMatchingRows(retrieved...) + case LocationsLocationSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLocation or a slice of LocationsLocation + // then run the AfterUpdateHooks on the slice + _, err = LocationsLocations.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsLocationSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocations.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLocation: + o.copyMatchingRows(retrieved) + case []*LocationsLocation: + o.copyMatchingRows(retrieved...) + case LocationsLocationSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLocation or a slice of LocationsLocation + // then run the AfterDeleteHooks on the slice + _, err = LocationsLocations.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsLocationSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsLocationSetter) error { + _, err := LocationsLocations.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsLocationSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsLocations.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsLocationSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsLocations.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// FromLocationLocationsLocationReplicators starts a query for related objects on locations_location_replicators +func (o *LocationsLocation) FromLocationLocationsLocationReplicators(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationReplicatorsQuery { + return LocationsLocationReplicators.Query(append(mods, + sm.Where(LocationsLocationReplicators.Columns.FromLocationID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os LocationsLocationSlice) FromLocationLocationsLocationReplicators(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationReplicatorsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocationReplicators.Query(append(mods, + sm.Where(mysql.Group(LocationsLocationReplicators.Columns.FromLocationID).OP("IN", PKArgExpr)), + )...) +} + +// ToLocationLocationsLocationReplicators starts a query for related objects on locations_location_replicators +func (o *LocationsLocation) ToLocationLocationsLocationReplicators(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationReplicatorsQuery { + return LocationsLocationReplicators.Query(append(mods, + sm.Where(LocationsLocationReplicators.Columns.ToLocationID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os LocationsLocationSlice) ToLocationLocationsLocationReplicators(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationReplicatorsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocationReplicators.Query(append(mods, + sm.Where(mysql.Group(LocationsLocationReplicators.Columns.ToLocationID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsLocation) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsLocationSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +// LocationLocationsLocationpipelines starts a query for related objects on locations_locationpipeline +func (o *LocationsLocation) LocationLocationsLocationpipelines(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationpipelinesQuery { + return LocationsLocationpipelines.Query(append(mods, + sm.Where(LocationsLocationpipelines.Columns.LocationID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsLocationSlice) LocationLocationsLocationpipelines(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationpipelinesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocationpipelines.Query(append(mods, + sm.Where(mysql.Group(LocationsLocationpipelines.Columns.LocationID).OP("IN", PKArgExpr)), + )...) +} + +// CurrentLocationLocationsPackages starts a query for related objects on locations_package +func (o *LocationsLocation) CurrentLocationLocationsPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.CurrentLocationID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsLocationSlice) CurrentLocationLocationsPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.CurrentLocationID).OP("IN", PKArgExpr)), + )...) +} + +// PointerFileLocationLocationsPackages starts a query for related objects on locations_package +func (o *LocationsLocation) PointerFileLocationLocationsPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.PointerFileLocationID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsLocationSlice) PointerFileLocationLocationsPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.PointerFileLocationID).OP("IN", PKArgExpr)), + )...) +} + +func insertLocationsLocationFromLocationLocationsLocationReplicators0(ctx context.Context, exec bob.Executor, locationsLocationReplicators1 []*LocationsLocationReplicatorSetter, locationsLocation0 *LocationsLocation) (LocationsLocationReplicatorSlice, error) { + for i := range locationsLocationReplicators1 { + locationsLocationReplicators1[i].FromLocationID = omit.From(locationsLocation0.ID) + } + + ret, err := LocationsLocationReplicators.Insert(bob.ToMods(locationsLocationReplicators1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsLocationFromLocationLocationsLocationReplicators0: %w", err) + } + + return ret, nil +} + +func attachLocationsLocationFromLocationLocationsLocationReplicators0(ctx context.Context, exec bob.Executor, count int, locationsLocationReplicators1 LocationsLocationReplicatorSlice, locationsLocation0 *LocationsLocation) (LocationsLocationReplicatorSlice, error) { + setter := &LocationsLocationReplicatorSetter{ + FromLocationID: omit.From(locationsLocation0.ID), + } + + err := locationsLocationReplicators1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationFromLocationLocationsLocationReplicators0: %w", err) + } + + return locationsLocationReplicators1, nil +} + +func (locationsLocation0 *LocationsLocation) InsertFromLocationLocationsLocationReplicators(ctx context.Context, exec bob.Executor, related ...*LocationsLocationReplicatorSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsLocationReplicators1, err := insertLocationsLocationFromLocationLocationsLocationReplicators0(ctx, exec, related, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.FromLocationLocationsLocationReplicators = append(locationsLocation0.R.FromLocationLocationsLocationReplicators, locationsLocationReplicators1...) + + for _, rel := range locationsLocationReplicators1 { + rel.R.FromLocationLocationsLocation = locationsLocation0 + } + return nil +} + +func (locationsLocation0 *LocationsLocation) AttachFromLocationLocationsLocationReplicators(ctx context.Context, exec bob.Executor, related ...*LocationsLocationReplicator) error { + if len(related) == 0 { + return nil + } + + var err error + locationsLocationReplicators1 := LocationsLocationReplicatorSlice(related) + + _, err = attachLocationsLocationFromLocationLocationsLocationReplicators0(ctx, exec, len(related), locationsLocationReplicators1, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.FromLocationLocationsLocationReplicators = append(locationsLocation0.R.FromLocationLocationsLocationReplicators, locationsLocationReplicators1...) + + for _, rel := range related { + rel.R.FromLocationLocationsLocation = locationsLocation0 + } + + return nil +} + +func insertLocationsLocationToLocationLocationsLocationReplicators0(ctx context.Context, exec bob.Executor, locationsLocationReplicators1 []*LocationsLocationReplicatorSetter, locationsLocation0 *LocationsLocation) (LocationsLocationReplicatorSlice, error) { + for i := range locationsLocationReplicators1 { + locationsLocationReplicators1[i].ToLocationID = omit.From(locationsLocation0.ID) + } + + ret, err := LocationsLocationReplicators.Insert(bob.ToMods(locationsLocationReplicators1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsLocationToLocationLocationsLocationReplicators0: %w", err) + } + + return ret, nil +} + +func attachLocationsLocationToLocationLocationsLocationReplicators0(ctx context.Context, exec bob.Executor, count int, locationsLocationReplicators1 LocationsLocationReplicatorSlice, locationsLocation0 *LocationsLocation) (LocationsLocationReplicatorSlice, error) { + setter := &LocationsLocationReplicatorSetter{ + ToLocationID: omit.From(locationsLocation0.ID), + } + + err := locationsLocationReplicators1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationToLocationLocationsLocationReplicators0: %w", err) + } + + return locationsLocationReplicators1, nil +} + +func (locationsLocation0 *LocationsLocation) InsertToLocationLocationsLocationReplicators(ctx context.Context, exec bob.Executor, related ...*LocationsLocationReplicatorSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsLocationReplicators1, err := insertLocationsLocationToLocationLocationsLocationReplicators0(ctx, exec, related, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.ToLocationLocationsLocationReplicators = append(locationsLocation0.R.ToLocationLocationsLocationReplicators, locationsLocationReplicators1...) + + for _, rel := range locationsLocationReplicators1 { + rel.R.ToLocationLocationsLocation = locationsLocation0 + } + return nil +} + +func (locationsLocation0 *LocationsLocation) AttachToLocationLocationsLocationReplicators(ctx context.Context, exec bob.Executor, related ...*LocationsLocationReplicator) error { + if len(related) == 0 { + return nil + } + + var err error + locationsLocationReplicators1 := LocationsLocationReplicatorSlice(related) + + _, err = attachLocationsLocationToLocationLocationsLocationReplicators0(ctx, exec, len(related), locationsLocationReplicators1, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.ToLocationLocationsLocationReplicators = append(locationsLocation0.R.ToLocationLocationsLocationReplicators, locationsLocationReplicators1...) + + for _, rel := range related { + rel.R.ToLocationLocationsLocation = locationsLocation0 + } + + return nil +} + +func attachLocationsLocationSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsLocation0 *LocationsLocation, locationsSpace1 *LocationsSpace) (*LocationsLocation, error) { + setter := &LocationsLocationSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsLocation0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationSpaceLocationsSpace0: %w", err) + } + + return locationsLocation0, nil +} + +func (locationsLocation0 *LocationsLocation) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsLocationSpaceLocationsSpace0(ctx, exec, 1, locationsLocation0, locationsSpace1) + if err != nil { + return err + } + + locationsLocation0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsLocations = append(locationsSpace1.R.SpaceLocationsLocations, locationsLocation0) + + return nil +} + +func (locationsLocation0 *LocationsLocation) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsLocationSpaceLocationsSpace0(ctx, exec, 1, locationsLocation0, locationsSpace1) + if err != nil { + return err + } + + locationsLocation0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsLocations = append(locationsSpace1.R.SpaceLocationsLocations, locationsLocation0) + + return nil +} + +func insertLocationsLocationLocationLocationsLocationpipelines0(ctx context.Context, exec bob.Executor, locationsLocationpipelines1 []*LocationsLocationpipelineSetter, locationsLocation0 *LocationsLocation) (LocationsLocationpipelineSlice, error) { + for i := range locationsLocationpipelines1 { + locationsLocationpipelines1[i].LocationID = omit.From(locationsLocation0.UUID) + } + + ret, err := LocationsLocationpipelines.Insert(bob.ToMods(locationsLocationpipelines1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsLocationLocationLocationsLocationpipelines0: %w", err) + } + + return ret, nil +} + +func attachLocationsLocationLocationLocationsLocationpipelines0(ctx context.Context, exec bob.Executor, count int, locationsLocationpipelines1 LocationsLocationpipelineSlice, locationsLocation0 *LocationsLocation) (LocationsLocationpipelineSlice, error) { + setter := &LocationsLocationpipelineSetter{ + LocationID: omit.From(locationsLocation0.UUID), + } + + err := locationsLocationpipelines1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationLocationLocationsLocationpipelines0: %w", err) + } + + return locationsLocationpipelines1, nil +} + +func (locationsLocation0 *LocationsLocation) InsertLocationLocationsLocationpipelines(ctx context.Context, exec bob.Executor, related ...*LocationsLocationpipelineSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsLocationpipelines1, err := insertLocationsLocationLocationLocationsLocationpipelines0(ctx, exec, related, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.LocationLocationsLocationpipelines = append(locationsLocation0.R.LocationLocationsLocationpipelines, locationsLocationpipelines1...) + + for _, rel := range locationsLocationpipelines1 { + rel.R.LocationLocationsLocation = locationsLocation0 + } + return nil +} + +func (locationsLocation0 *LocationsLocation) AttachLocationLocationsLocationpipelines(ctx context.Context, exec bob.Executor, related ...*LocationsLocationpipeline) error { + if len(related) == 0 { + return nil + } + + var err error + locationsLocationpipelines1 := LocationsLocationpipelineSlice(related) + + _, err = attachLocationsLocationLocationLocationsLocationpipelines0(ctx, exec, len(related), locationsLocationpipelines1, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.LocationLocationsLocationpipelines = append(locationsLocation0.R.LocationLocationsLocationpipelines, locationsLocationpipelines1...) + + for _, rel := range related { + rel.R.LocationLocationsLocation = locationsLocation0 + } + + return nil +} + +func insertLocationsLocationCurrentLocationLocationsPackages0(ctx context.Context, exec bob.Executor, locationsPackages1 []*LocationsPackageSetter, locationsLocation0 *LocationsLocation) (LocationsPackageSlice, error) { + for i := range locationsPackages1 { + locationsPackages1[i].CurrentLocationID = omit.From(locationsLocation0.UUID) + } + + ret, err := LocationsPackages.Insert(bob.ToMods(locationsPackages1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsLocationCurrentLocationLocationsPackages0: %w", err) + } + + return ret, nil +} + +func attachLocationsLocationCurrentLocationLocationsPackages0(ctx context.Context, exec bob.Executor, count int, locationsPackages1 LocationsPackageSlice, locationsLocation0 *LocationsLocation) (LocationsPackageSlice, error) { + setter := &LocationsPackageSetter{ + CurrentLocationID: omit.From(locationsLocation0.UUID), + } + + err := locationsPackages1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationCurrentLocationLocationsPackages0: %w", err) + } + + return locationsPackages1, nil +} + +func (locationsLocation0 *LocationsLocation) InsertCurrentLocationLocationsPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackageSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsPackages1, err := insertLocationsLocationCurrentLocationLocationsPackages0(ctx, exec, related, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.CurrentLocationLocationsPackages = append(locationsLocation0.R.CurrentLocationLocationsPackages, locationsPackages1...) + + for _, rel := range locationsPackages1 { + rel.R.CurrentLocationLocationsLocation = locationsLocation0 + } + return nil +} + +func (locationsLocation0 *LocationsLocation) AttachCurrentLocationLocationsPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackage) error { + if len(related) == 0 { + return nil + } + + var err error + locationsPackages1 := LocationsPackageSlice(related) + + _, err = attachLocationsLocationCurrentLocationLocationsPackages0(ctx, exec, len(related), locationsPackages1, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.CurrentLocationLocationsPackages = append(locationsLocation0.R.CurrentLocationLocationsPackages, locationsPackages1...) + + for _, rel := range related { + rel.R.CurrentLocationLocationsLocation = locationsLocation0 + } + + return nil +} + +func insertLocationsLocationPointerFileLocationLocationsPackages0(ctx context.Context, exec bob.Executor, locationsPackages1 []*LocationsPackageSetter, locationsLocation0 *LocationsLocation) (LocationsPackageSlice, error) { + for i := range locationsPackages1 { + locationsPackages1[i].PointerFileLocationID = omitnull.From(locationsLocation0.UUID) + } + + ret, err := LocationsPackages.Insert(bob.ToMods(locationsPackages1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsLocationPointerFileLocationLocationsPackages0: %w", err) + } + + return ret, nil +} + +func attachLocationsLocationPointerFileLocationLocationsPackages0(ctx context.Context, exec bob.Executor, count int, locationsPackages1 LocationsPackageSlice, locationsLocation0 *LocationsLocation) (LocationsPackageSlice, error) { + setter := &LocationsPackageSetter{ + PointerFileLocationID: omitnull.From(locationsLocation0.UUID), + } + + err := locationsPackages1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationPointerFileLocationLocationsPackages0: %w", err) + } + + return locationsPackages1, nil +} + +func (locationsLocation0 *LocationsLocation) InsertPointerFileLocationLocationsPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackageSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsPackages1, err := insertLocationsLocationPointerFileLocationLocationsPackages0(ctx, exec, related, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.PointerFileLocationLocationsPackages = append(locationsLocation0.R.PointerFileLocationLocationsPackages, locationsPackages1...) + + for _, rel := range locationsPackages1 { + rel.R.PointerFileLocationLocationsLocation = locationsLocation0 + } + return nil +} + +func (locationsLocation0 *LocationsLocation) AttachPointerFileLocationLocationsPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackage) error { + if len(related) == 0 { + return nil + } + + var err error + locationsPackages1 := LocationsPackageSlice(related) + + _, err = attachLocationsLocationPointerFileLocationLocationsPackages0(ctx, exec, len(related), locationsPackages1, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.PointerFileLocationLocationsPackages = append(locationsLocation0.R.PointerFileLocationLocationsPackages, locationsPackages1...) + + for _, rel := range related { + rel.R.PointerFileLocationLocationsLocation = locationsLocation0 + } + + return nil +} + +type locationsLocationWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UUID mysql.WhereMod[Q, string] + Purpose mysql.WhereMod[Q, string] + RelativePath mysql.WhereMod[Q, string] + Description mysql.WhereNullMod[Q, string] + Quota mysql.WhereNullMod[Q, int64] + Used mysql.WhereMod[Q, int64] + Enabled mysql.WhereMod[Q, bool] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsLocationWhere[Q]) AliasedAs(alias string) locationsLocationWhere[Q] { + return buildLocationsLocationWhere[Q](buildLocationsLocationColumns(alias)) +} + +func buildLocationsLocationWhere[Q mysql.Filterable](cols locationsLocationColumns) locationsLocationWhere[Q] { + return locationsLocationWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UUID: mysql.Where[Q, string](cols.UUID), + Purpose: mysql.Where[Q, string](cols.Purpose), + RelativePath: mysql.Where[Q, string](cols.RelativePath), + Description: mysql.WhereNull[Q, string](cols.Description), + Quota: mysql.WhereNull[Q, int64](cols.Quota), + Used: mysql.Where[Q, int64](cols.Used), + Enabled: mysql.Where[Q, bool](cols.Enabled), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsLocation) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "FromLocationLocationsLocationReplicators": + rels, ok := retrieved.(LocationsLocationReplicatorSlice) + if !ok { + return fmt.Errorf("locationsLocation cannot load %T as %q", retrieved, name) + } + + o.R.FromLocationLocationsLocationReplicators = rels + + for _, rel := range rels { + if rel != nil { + rel.R.FromLocationLocationsLocation = o + } + } + return nil + case "ToLocationLocationsLocationReplicators": + rels, ok := retrieved.(LocationsLocationReplicatorSlice) + if !ok { + return fmt.Errorf("locationsLocation cannot load %T as %q", retrieved, name) + } + + o.R.ToLocationLocationsLocationReplicators = rels + + for _, rel := range rels { + if rel != nil { + rel.R.ToLocationLocationsLocation = o + } + } + return nil + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsLocation cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsLocations = LocationsLocationSlice{o} + } + return nil + case "LocationLocationsLocationpipelines": + rels, ok := retrieved.(LocationsLocationpipelineSlice) + if !ok { + return fmt.Errorf("locationsLocation cannot load %T as %q", retrieved, name) + } + + o.R.LocationLocationsLocationpipelines = rels + + for _, rel := range rels { + if rel != nil { + rel.R.LocationLocationsLocation = o + } + } + return nil + case "CurrentLocationLocationsPackages": + rels, ok := retrieved.(LocationsPackageSlice) + if !ok { + return fmt.Errorf("locationsLocation cannot load %T as %q", retrieved, name) + } + + o.R.CurrentLocationLocationsPackages = rels + + for _, rel := range rels { + if rel != nil { + rel.R.CurrentLocationLocationsLocation = o + } + } + return nil + case "PointerFileLocationLocationsPackages": + rels, ok := retrieved.(LocationsPackageSlice) + if !ok { + return fmt.Errorf("locationsLocation cannot load %T as %q", retrieved, name) + } + + o.R.PointerFileLocationLocationsPackages = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PointerFileLocationLocationsLocation = o + } + } + return nil + default: + return fmt.Errorf("locationsLocation has no relationship %q", name) + } +} + +type locationsLocationPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsLocationPreloader() locationsLocationPreloader { + return locationsLocationPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsLocations, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsLocationThenLoader[Q orm.Loadable] struct { + FromLocationLocationsLocationReplicators func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ToLocationLocationsLocationReplicators func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + LocationLocationsLocationpipelines func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + CurrentLocationLocationsPackages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PointerFileLocationLocationsPackages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsLocationThenLoader[Q orm.Loadable]() locationsLocationThenLoader[Q] { + type FromLocationLocationsLocationReplicatorsLoadInterface interface { + LoadFromLocationLocationsLocationReplicators(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ToLocationLocationsLocationReplicatorsLoadInterface interface { + LoadToLocationLocationsLocationReplicators(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type LocationLocationsLocationpipelinesLoadInterface interface { + LoadLocationLocationsLocationpipelines(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type CurrentLocationLocationsPackagesLoadInterface interface { + LoadCurrentLocationLocationsPackages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PointerFileLocationLocationsPackagesLoadInterface interface { + LoadPointerFileLocationLocationsPackages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsLocationThenLoader[Q]{ + FromLocationLocationsLocationReplicators: thenLoadBuilder[Q]( + "FromLocationLocationsLocationReplicators", + func(ctx context.Context, exec bob.Executor, retrieved FromLocationLocationsLocationReplicatorsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadFromLocationLocationsLocationReplicators(ctx, exec, mods...) + }, + ), + ToLocationLocationsLocationReplicators: thenLoadBuilder[Q]( + "ToLocationLocationsLocationReplicators", + func(ctx context.Context, exec bob.Executor, retrieved ToLocationLocationsLocationReplicatorsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadToLocationLocationsLocationReplicators(ctx, exec, mods...) + }, + ), + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + LocationLocationsLocationpipelines: thenLoadBuilder[Q]( + "LocationLocationsLocationpipelines", + func(ctx context.Context, exec bob.Executor, retrieved LocationLocationsLocationpipelinesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadLocationLocationsLocationpipelines(ctx, exec, mods...) + }, + ), + CurrentLocationLocationsPackages: thenLoadBuilder[Q]( + "CurrentLocationLocationsPackages", + func(ctx context.Context, exec bob.Executor, retrieved CurrentLocationLocationsPackagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadCurrentLocationLocationsPackages(ctx, exec, mods...) + }, + ), + PointerFileLocationLocationsPackages: thenLoadBuilder[Q]( + "PointerFileLocationLocationsPackages", + func(ctx context.Context, exec bob.Executor, retrieved PointerFileLocationLocationsPackagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPointerFileLocationLocationsPackages(ctx, exec, mods...) + }, + ), + } +} + +// LoadFromLocationLocationsLocationReplicators loads the locationsLocation's FromLocationLocationsLocationReplicators into the .R struct +func (o *LocationsLocation) LoadFromLocationLocationsLocationReplicators(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.FromLocationLocationsLocationReplicators = nil + + related, err := o.FromLocationLocationsLocationReplicators(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.FromLocationLocationsLocation = o + } + + o.R.FromLocationLocationsLocationReplicators = related + return nil +} + +// LoadFromLocationLocationsLocationReplicators loads the locationsLocation's FromLocationLocationsLocationReplicators into the .R struct +func (os LocationsLocationSlice) LoadFromLocationLocationsLocationReplicators(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocationReplicators, err := os.FromLocationLocationsLocationReplicators(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.FromLocationLocationsLocationReplicators = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocationReplicators { + + if !(o.ID == rel.FromLocationID) { + continue + } + + rel.R.FromLocationLocationsLocation = o + + o.R.FromLocationLocationsLocationReplicators = append(o.R.FromLocationLocationsLocationReplicators, rel) + } + } + + return nil +} + +// LoadToLocationLocationsLocationReplicators loads the locationsLocation's ToLocationLocationsLocationReplicators into the .R struct +func (o *LocationsLocation) LoadToLocationLocationsLocationReplicators(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ToLocationLocationsLocationReplicators = nil + + related, err := o.ToLocationLocationsLocationReplicators(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.ToLocationLocationsLocation = o + } + + o.R.ToLocationLocationsLocationReplicators = related + return nil +} + +// LoadToLocationLocationsLocationReplicators loads the locationsLocation's ToLocationLocationsLocationReplicators into the .R struct +func (os LocationsLocationSlice) LoadToLocationLocationsLocationReplicators(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocationReplicators, err := os.ToLocationLocationsLocationReplicators(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.ToLocationLocationsLocationReplicators = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocationReplicators { + + if !(o.ID == rel.ToLocationID) { + continue + } + + rel.R.ToLocationLocationsLocation = o + + o.R.ToLocationLocationsLocationReplicators = append(o.R.ToLocationLocationsLocationReplicators, rel) + } + } + + return nil +} + +// LoadSpaceLocationsSpace loads the locationsLocation's SpaceLocationsSpace into the .R struct +func (o *LocationsLocation) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsLocations = LocationsLocationSlice{o} + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsLocation's SpaceLocationsSpace into the .R struct +func (os LocationsLocationSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsLocations = append(rel.R.SpaceLocationsLocations, o) + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +// LoadLocationLocationsLocationpipelines loads the locationsLocation's LocationLocationsLocationpipelines into the .R struct +func (o *LocationsLocation) LoadLocationLocationsLocationpipelines(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.LocationLocationsLocationpipelines = nil + + related, err := o.LocationLocationsLocationpipelines(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.LocationLocationsLocation = o + } + + o.R.LocationLocationsLocationpipelines = related + return nil +} + +// LoadLocationLocationsLocationpipelines loads the locationsLocation's LocationLocationsLocationpipelines into the .R struct +func (os LocationsLocationSlice) LoadLocationLocationsLocationpipelines(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocationpipelines, err := os.LocationLocationsLocationpipelines(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.LocationLocationsLocationpipelines = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocationpipelines { + + if !(o.UUID == rel.LocationID) { + continue + } + + rel.R.LocationLocationsLocation = o + + o.R.LocationLocationsLocationpipelines = append(o.R.LocationLocationsLocationpipelines, rel) + } + } + + return nil +} + +// LoadCurrentLocationLocationsPackages loads the locationsLocation's CurrentLocationLocationsPackages into the .R struct +func (o *LocationsLocation) LoadCurrentLocationLocationsPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.CurrentLocationLocationsPackages = nil + + related, err := o.CurrentLocationLocationsPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.CurrentLocationLocationsLocation = o + } + + o.R.CurrentLocationLocationsPackages = related + return nil +} + +// LoadCurrentLocationLocationsPackages loads the locationsLocation's CurrentLocationLocationsPackages into the .R struct +func (os LocationsLocationSlice) LoadCurrentLocationLocationsPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.CurrentLocationLocationsPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.CurrentLocationLocationsPackages = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !(o.UUID == rel.CurrentLocationID) { + continue + } + + rel.R.CurrentLocationLocationsLocation = o + + o.R.CurrentLocationLocationsPackages = append(o.R.CurrentLocationLocationsPackages, rel) + } + } + + return nil +} + +// LoadPointerFileLocationLocationsPackages loads the locationsLocation's PointerFileLocationLocationsPackages into the .R struct +func (o *LocationsLocation) LoadPointerFileLocationLocationsPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PointerFileLocationLocationsPackages = nil + + related, err := o.PointerFileLocationLocationsPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PointerFileLocationLocationsLocation = o + } + + o.R.PointerFileLocationLocationsPackages = related + return nil +} + +// LoadPointerFileLocationLocationsPackages loads the locationsLocation's PointerFileLocationLocationsPackages into the .R struct +func (os LocationsLocationSlice) LoadPointerFileLocationLocationsPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.PointerFileLocationLocationsPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PointerFileLocationLocationsPackages = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !rel.PointerFileLocationID.IsValue() { + continue + } + if !(rel.PointerFileLocationID.IsValue() && o.UUID == rel.PointerFileLocationID.MustGet()) { + continue + } + + rel.R.PointerFileLocationLocationsLocation = o + + o.R.PointerFileLocationLocationsPackages = append(o.R.PointerFileLocationLocationsPackages, rel) + } + } + + return nil +} + +type locationsLocationJoins[Q dialect.Joinable] struct { + typ string + FromLocationLocationsLocationReplicators modAs[Q, locationsLocationReplicatorColumns] + ToLocationLocationsLocationReplicators modAs[Q, locationsLocationReplicatorColumns] + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] + LocationLocationsLocationpipelines modAs[Q, locationsLocationpipelineColumns] + CurrentLocationLocationsPackages modAs[Q, locationsPackageColumns] + PointerFileLocationLocationsPackages modAs[Q, locationsPackageColumns] +} + +func (j locationsLocationJoins[Q]) aliasedAs(alias string) locationsLocationJoins[Q] { + return buildLocationsLocationJoins[Q](buildLocationsLocationColumns(alias), j.typ) +} + +func buildLocationsLocationJoins[Q dialect.Joinable](cols locationsLocationColumns, typ string) locationsLocationJoins[Q] { + return locationsLocationJoins[Q]{ + typ: typ, + FromLocationLocationsLocationReplicators: modAs[Q, locationsLocationReplicatorColumns]{ + c: LocationsLocationReplicators.Columns, + f: func(to locationsLocationReplicatorColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocationReplicators.Name().As(to.Alias())).On( + to.FromLocationID.EQ(cols.ID), + )) + } + + return mods + }, + }, + ToLocationLocationsLocationReplicators: modAs[Q, locationsLocationReplicatorColumns]{ + c: LocationsLocationReplicators.Columns, + f: func(to locationsLocationReplicatorColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocationReplicators.Name().As(to.Alias())).On( + to.ToLocationID.EQ(cols.ID), + )) + } + + return mods + }, + }, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + LocationLocationsLocationpipelines: modAs[Q, locationsLocationpipelineColumns]{ + c: LocationsLocationpipelines.Columns, + f: func(to locationsLocationpipelineColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocationpipelines.Name().As(to.Alias())).On( + to.LocationID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + CurrentLocationLocationsPackages: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.CurrentLocationID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + PointerFileLocationLocationsPackages: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.PointerFileLocationID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_location_replicators.bob.go b/database/mcp/models/locations_location_replicators.bob.go new file mode 100644 index 0000000..437a7f0 --- /dev/null +++ b/database/mcp/models/locations_location_replicators.bob.go @@ -0,0 +1,787 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsLocationReplicator is an object representing the database table. +type LocationsLocationReplicator struct { + ID int32 `db:"id,pk,autoincr" ` + FromLocationID int32 `db:"from_location_id" ` + ToLocationID int32 `db:"to_location_id" ` + + R locationsLocationReplicatorR `db:"-" ` +} + +// LocationsLocationReplicatorSlice is an alias for a slice of pointers to LocationsLocationReplicator. +// This should almost always be used instead of []*LocationsLocationReplicator. +type LocationsLocationReplicatorSlice []*LocationsLocationReplicator + +// LocationsLocationReplicators contains methods to work with the locations_location_replicators table +var LocationsLocationReplicators = mysql.NewTablex[*LocationsLocationReplicator, LocationsLocationReplicatorSlice, *LocationsLocationReplicatorSetter]("locations_location_replicators", buildLocationsLocationReplicatorColumns("locations_location_replicators"), []string{"id"}, []string{"from_location_id", "to_location_id"}) + +// LocationsLocationReplicatorsQuery is a query on the locations_location_replicators table +type LocationsLocationReplicatorsQuery = *mysql.ViewQuery[*LocationsLocationReplicator, LocationsLocationReplicatorSlice] + +// locationsLocationReplicatorR is where relationships are stored. +type locationsLocationReplicatorR struct { + FromLocationLocationsLocation *LocationsLocation // locations_location_r_from_location_id_3b9a55f5_fk_locations + ToLocationLocationsLocation *LocationsLocation // locations_location_r_to_location_id_27be9af1_fk_locations +} + +func buildLocationsLocationReplicatorColumns(alias string) locationsLocationReplicatorColumns { + return locationsLocationReplicatorColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "from_location_id", "to_location_id", + ).WithParent("locations_location_replicators"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + FromLocationID: mysql.Quote(alias, "from_location_id"), + ToLocationID: mysql.Quote(alias, "to_location_id"), + } +} + +type locationsLocationReplicatorColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + FromLocationID mysql.Expression + ToLocationID mysql.Expression +} + +func (c locationsLocationReplicatorColumns) Alias() string { + return c.tableAlias +} + +func (locationsLocationReplicatorColumns) AliasedAs(alias string) locationsLocationReplicatorColumns { + return buildLocationsLocationReplicatorColumns(alias) +} + +// LocationsLocationReplicatorSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsLocationReplicatorSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + FromLocationID omit.Val[int32] `db:"from_location_id" ` + ToLocationID omit.Val[int32] `db:"to_location_id" ` +} + +func (s LocationsLocationReplicatorSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.FromLocationID.IsValue() { + vals = append(vals, "from_location_id") + } + if s.ToLocationID.IsValue() { + vals = append(vals, "to_location_id") + } + return vals +} + +func (s LocationsLocationReplicatorSetter) Overwrite(t *LocationsLocationReplicator) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.FromLocationID.IsValue() { + t.FromLocationID = s.FromLocationID.MustGet() + } + if s.ToLocationID.IsValue() { + t.ToLocationID = s.ToLocationID.MustGet() + } +} + +func (s *LocationsLocationReplicatorSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocationReplicators.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.FromLocationID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.FromLocationID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ToLocationID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ToLocationID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsLocationReplicatorSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_location_replicators")...) +} + +func (s LocationsLocationReplicatorSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.FromLocationID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "from_location_id")...), + mysql.Arg(s.FromLocationID), + }}) + } + + if s.ToLocationID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "to_location_id")...), + mysql.Arg(s.ToLocationID), + }}) + } + + return exprs +} + +// FindLocationsLocationReplicator retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsLocationReplicator(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsLocationReplicator, error) { + if len(cols) == 0 { + return LocationsLocationReplicators.Query( + sm.Where(LocationsLocationReplicators.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsLocationReplicators.Query( + sm.Where(LocationsLocationReplicators.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsLocationReplicators.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsLocationReplicatorExists checks the presence of a single record by primary key +func LocationsLocationReplicatorExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsLocationReplicators.Query( + sm.Where(LocationsLocationReplicators.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsLocationReplicator is retrieved from the database +func (o *LocationsLocationReplicator) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLocationReplicators.AfterSelectHooks.RunHooks(ctx, exec, LocationsLocationReplicatorSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsLocationReplicators.AfterInsertHooks.RunHooks(ctx, exec, LocationsLocationReplicatorSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsLocationReplicators.AfterUpdateHooks.RunHooks(ctx, exec, LocationsLocationReplicatorSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsLocationReplicators.AfterDeleteHooks.RunHooks(ctx, exec, LocationsLocationReplicatorSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsLocationReplicator +func (o *LocationsLocationReplicator) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsLocationReplicator) pkEQ() dialect.Expression { + return mysql.Quote("locations_location_replicators", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsLocationReplicator +func (o *LocationsLocationReplicator) Update(ctx context.Context, exec bob.Executor, s *LocationsLocationReplicatorSetter) error { + _, err := LocationsLocationReplicators.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsLocationReplicator record with an executor +func (o *LocationsLocationReplicator) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsLocationReplicators.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsLocationReplicator using the executor +func (o *LocationsLocationReplicator) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsLocationReplicators.Query( + sm.Where(LocationsLocationReplicators.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsLocationReplicatorSlice is retrieved from the database +func (o LocationsLocationReplicatorSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLocationReplicators.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsLocationReplicators.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsLocationReplicators.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsLocationReplicators.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsLocationReplicatorSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_location_replicators", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsLocationReplicatorSlice) copyMatchingRows(from ...*LocationsLocationReplicator) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsLocationReplicatorSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocationReplicators.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLocationReplicator: + o.copyMatchingRows(retrieved) + case []*LocationsLocationReplicator: + o.copyMatchingRows(retrieved...) + case LocationsLocationReplicatorSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLocationReplicator or a slice of LocationsLocationReplicator + // then run the AfterUpdateHooks on the slice + _, err = LocationsLocationReplicators.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsLocationReplicatorSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocationReplicators.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLocationReplicator: + o.copyMatchingRows(retrieved) + case []*LocationsLocationReplicator: + o.copyMatchingRows(retrieved...) + case LocationsLocationReplicatorSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLocationReplicator or a slice of LocationsLocationReplicator + // then run the AfterDeleteHooks on the slice + _, err = LocationsLocationReplicators.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsLocationReplicatorSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsLocationReplicatorSetter) error { + _, err := LocationsLocationReplicators.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsLocationReplicatorSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsLocationReplicators.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsLocationReplicatorSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsLocationReplicators.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// FromLocationLocationsLocation starts a query for related objects on locations_location +func (o *LocationsLocationReplicator) FromLocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + return LocationsLocations.Query(append(mods, + sm.Where(LocationsLocations.Columns.ID.EQ(mysql.Arg(o.FromLocationID))), + )...) +} + +func (os LocationsLocationReplicatorSlice) FromLocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.FromLocationID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocations.Query(append(mods, + sm.Where(mysql.Group(LocationsLocations.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// ToLocationLocationsLocation starts a query for related objects on locations_location +func (o *LocationsLocationReplicator) ToLocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + return LocationsLocations.Query(append(mods, + sm.Where(LocationsLocations.Columns.ID.EQ(mysql.Arg(o.ToLocationID))), + )...) +} + +func (os LocationsLocationReplicatorSlice) ToLocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ToLocationID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocations.Query(append(mods, + sm.Where(mysql.Group(LocationsLocations.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsLocationReplicatorFromLocationLocationsLocation0(ctx context.Context, exec bob.Executor, count int, locationsLocationReplicator0 *LocationsLocationReplicator, locationsLocation1 *LocationsLocation) (*LocationsLocationReplicator, error) { + setter := &LocationsLocationReplicatorSetter{ + FromLocationID: omit.From(locationsLocation1.ID), + } + + err := locationsLocationReplicator0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationReplicatorFromLocationLocationsLocation0: %w", err) + } + + return locationsLocationReplicator0, nil +} + +func (locationsLocationReplicator0 *LocationsLocationReplicator) InsertFromLocationLocationsLocation(ctx context.Context, exec bob.Executor, related *LocationsLocationSetter) error { + var err error + + locationsLocation1, err := LocationsLocations.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsLocationReplicatorFromLocationLocationsLocation0(ctx, exec, 1, locationsLocationReplicator0, locationsLocation1) + if err != nil { + return err + } + + locationsLocationReplicator0.R.FromLocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.FromLocationLocationsLocationReplicators = append(locationsLocation1.R.FromLocationLocationsLocationReplicators, locationsLocationReplicator0) + + return nil +} + +func (locationsLocationReplicator0 *LocationsLocationReplicator) AttachFromLocationLocationsLocation(ctx context.Context, exec bob.Executor, locationsLocation1 *LocationsLocation) error { + var err error + + _, err = attachLocationsLocationReplicatorFromLocationLocationsLocation0(ctx, exec, 1, locationsLocationReplicator0, locationsLocation1) + if err != nil { + return err + } + + locationsLocationReplicator0.R.FromLocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.FromLocationLocationsLocationReplicators = append(locationsLocation1.R.FromLocationLocationsLocationReplicators, locationsLocationReplicator0) + + return nil +} + +func attachLocationsLocationReplicatorToLocationLocationsLocation0(ctx context.Context, exec bob.Executor, count int, locationsLocationReplicator0 *LocationsLocationReplicator, locationsLocation1 *LocationsLocation) (*LocationsLocationReplicator, error) { + setter := &LocationsLocationReplicatorSetter{ + ToLocationID: omit.From(locationsLocation1.ID), + } + + err := locationsLocationReplicator0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationReplicatorToLocationLocationsLocation0: %w", err) + } + + return locationsLocationReplicator0, nil +} + +func (locationsLocationReplicator0 *LocationsLocationReplicator) InsertToLocationLocationsLocation(ctx context.Context, exec bob.Executor, related *LocationsLocationSetter) error { + var err error + + locationsLocation1, err := LocationsLocations.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsLocationReplicatorToLocationLocationsLocation0(ctx, exec, 1, locationsLocationReplicator0, locationsLocation1) + if err != nil { + return err + } + + locationsLocationReplicator0.R.ToLocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.ToLocationLocationsLocationReplicators = append(locationsLocation1.R.ToLocationLocationsLocationReplicators, locationsLocationReplicator0) + + return nil +} + +func (locationsLocationReplicator0 *LocationsLocationReplicator) AttachToLocationLocationsLocation(ctx context.Context, exec bob.Executor, locationsLocation1 *LocationsLocation) error { + var err error + + _, err = attachLocationsLocationReplicatorToLocationLocationsLocation0(ctx, exec, 1, locationsLocationReplicator0, locationsLocation1) + if err != nil { + return err + } + + locationsLocationReplicator0.R.ToLocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.ToLocationLocationsLocationReplicators = append(locationsLocation1.R.ToLocationLocationsLocationReplicators, locationsLocationReplicator0) + + return nil +} + +type locationsLocationReplicatorWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + FromLocationID mysql.WhereMod[Q, int32] + ToLocationID mysql.WhereMod[Q, int32] +} + +func (locationsLocationReplicatorWhere[Q]) AliasedAs(alias string) locationsLocationReplicatorWhere[Q] { + return buildLocationsLocationReplicatorWhere[Q](buildLocationsLocationReplicatorColumns(alias)) +} + +func buildLocationsLocationReplicatorWhere[Q mysql.Filterable](cols locationsLocationReplicatorColumns) locationsLocationReplicatorWhere[Q] { + return locationsLocationReplicatorWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + FromLocationID: mysql.Where[Q, int32](cols.FromLocationID), + ToLocationID: mysql.Where[Q, int32](cols.ToLocationID), + } +} + +func (o *LocationsLocationReplicator) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "FromLocationLocationsLocation": + rel, ok := retrieved.(*LocationsLocation) + if !ok { + return fmt.Errorf("locationsLocationReplicator cannot load %T as %q", retrieved, name) + } + + o.R.FromLocationLocationsLocation = rel + + if rel != nil { + rel.R.FromLocationLocationsLocationReplicators = LocationsLocationReplicatorSlice{o} + } + return nil + case "ToLocationLocationsLocation": + rel, ok := retrieved.(*LocationsLocation) + if !ok { + return fmt.Errorf("locationsLocationReplicator cannot load %T as %q", retrieved, name) + } + + o.R.ToLocationLocationsLocation = rel + + if rel != nil { + rel.R.ToLocationLocationsLocationReplicators = LocationsLocationReplicatorSlice{o} + } + return nil + default: + return fmt.Errorf("locationsLocationReplicator has no relationship %q", name) + } +} + +type locationsLocationReplicatorPreloader struct { + FromLocationLocationsLocation func(...mysql.PreloadOption) mysql.Preloader + ToLocationLocationsLocation func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsLocationReplicatorPreloader() locationsLocationReplicatorPreloader { + return locationsLocationReplicatorPreloader{ + FromLocationLocationsLocation: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsLocation, LocationsLocationSlice](mysql.PreloadRel{ + Name: "FromLocationLocationsLocation", + Sides: []mysql.PreloadSide{ + { + From: LocationsLocationReplicators, + To: LocationsLocations, + FromColumns: []string{"from_location_id"}, + ToColumns: []string{"id"}, + }, + }, + }, LocationsLocations.Columns.Names(), opts...) + }, + ToLocationLocationsLocation: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsLocation, LocationsLocationSlice](mysql.PreloadRel{ + Name: "ToLocationLocationsLocation", + Sides: []mysql.PreloadSide{ + { + From: LocationsLocationReplicators, + To: LocationsLocations, + FromColumns: []string{"to_location_id"}, + ToColumns: []string{"id"}, + }, + }, + }, LocationsLocations.Columns.Names(), opts...) + }, + } +} + +type locationsLocationReplicatorThenLoader[Q orm.Loadable] struct { + FromLocationLocationsLocation func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ToLocationLocationsLocation func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsLocationReplicatorThenLoader[Q orm.Loadable]() locationsLocationReplicatorThenLoader[Q] { + type FromLocationLocationsLocationLoadInterface interface { + LoadFromLocationLocationsLocation(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ToLocationLocationsLocationLoadInterface interface { + LoadToLocationLocationsLocation(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsLocationReplicatorThenLoader[Q]{ + FromLocationLocationsLocation: thenLoadBuilder[Q]( + "FromLocationLocationsLocation", + func(ctx context.Context, exec bob.Executor, retrieved FromLocationLocationsLocationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadFromLocationLocationsLocation(ctx, exec, mods...) + }, + ), + ToLocationLocationsLocation: thenLoadBuilder[Q]( + "ToLocationLocationsLocation", + func(ctx context.Context, exec bob.Executor, retrieved ToLocationLocationsLocationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadToLocationLocationsLocation(ctx, exec, mods...) + }, + ), + } +} + +// LoadFromLocationLocationsLocation loads the locationsLocationReplicator's FromLocationLocationsLocation into the .R struct +func (o *LocationsLocationReplicator) LoadFromLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.FromLocationLocationsLocation = nil + + related, err := o.FromLocationLocationsLocation(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.FromLocationLocationsLocationReplicators = LocationsLocationReplicatorSlice{o} + + o.R.FromLocationLocationsLocation = related + return nil +} + +// LoadFromLocationLocationsLocation loads the locationsLocationReplicator's FromLocationLocationsLocation into the .R struct +func (os LocationsLocationReplicatorSlice) LoadFromLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocations, err := os.FromLocationLocationsLocation(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocations { + + if !(o.FromLocationID == rel.ID) { + continue + } + + rel.R.FromLocationLocationsLocationReplicators = append(rel.R.FromLocationLocationsLocationReplicators, o) + + o.R.FromLocationLocationsLocation = rel + break + } + } + + return nil +} + +// LoadToLocationLocationsLocation loads the locationsLocationReplicator's ToLocationLocationsLocation into the .R struct +func (o *LocationsLocationReplicator) LoadToLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ToLocationLocationsLocation = nil + + related, err := o.ToLocationLocationsLocation(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.ToLocationLocationsLocationReplicators = LocationsLocationReplicatorSlice{o} + + o.R.ToLocationLocationsLocation = related + return nil +} + +// LoadToLocationLocationsLocation loads the locationsLocationReplicator's ToLocationLocationsLocation into the .R struct +func (os LocationsLocationReplicatorSlice) LoadToLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocations, err := os.ToLocationLocationsLocation(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocations { + + if !(o.ToLocationID == rel.ID) { + continue + } + + rel.R.ToLocationLocationsLocationReplicators = append(rel.R.ToLocationLocationsLocationReplicators, o) + + o.R.ToLocationLocationsLocation = rel + break + } + } + + return nil +} + +type locationsLocationReplicatorJoins[Q dialect.Joinable] struct { + typ string + FromLocationLocationsLocation modAs[Q, locationsLocationColumns] + ToLocationLocationsLocation modAs[Q, locationsLocationColumns] +} + +func (j locationsLocationReplicatorJoins[Q]) aliasedAs(alias string) locationsLocationReplicatorJoins[Q] { + return buildLocationsLocationReplicatorJoins[Q](buildLocationsLocationReplicatorColumns(alias), j.typ) +} + +func buildLocationsLocationReplicatorJoins[Q dialect.Joinable](cols locationsLocationReplicatorColumns, typ string) locationsLocationReplicatorJoins[Q] { + return locationsLocationReplicatorJoins[Q]{ + typ: typ, + FromLocationLocationsLocation: modAs[Q, locationsLocationColumns]{ + c: LocationsLocations.Columns, + f: func(to locationsLocationColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocations.Name().As(to.Alias())).On( + to.ID.EQ(cols.FromLocationID), + )) + } + + return mods + }, + }, + ToLocationLocationsLocation: modAs[Q, locationsLocationColumns]{ + c: LocationsLocations.Columns, + f: func(to locationsLocationColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocations.Name().As(to.Alias())).On( + to.ID.EQ(cols.ToLocationID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_locationpipeline.bob.go b/database/mcp/models/locations_locationpipeline.bob.go new file mode 100644 index 0000000..c64e2c2 --- /dev/null +++ b/database/mcp/models/locations_locationpipeline.bob.go @@ -0,0 +1,787 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsLocationpipeline is an object representing the database table. +type LocationsLocationpipeline struct { + ID int32 `db:"id,pk,autoincr" ` + LocationID string `db:"location_id" ` + PipelineID string `db:"pipeline_id" ` + + R locationsLocationpipelineR `db:"-" ` +} + +// LocationsLocationpipelineSlice is an alias for a slice of pointers to LocationsLocationpipeline. +// This should almost always be used instead of []*LocationsLocationpipeline. +type LocationsLocationpipelineSlice []*LocationsLocationpipeline + +// LocationsLocationpipelines contains methods to work with the locations_locationpipeline table +var LocationsLocationpipelines = mysql.NewTablex[*LocationsLocationpipeline, LocationsLocationpipelineSlice, *LocationsLocationpipelineSetter]("locations_locationpipeline", buildLocationsLocationpipelineColumns("locations_locationpipeline"), []string{"id"}) + +// LocationsLocationpipelinesQuery is a query on the locations_locationpipeline table +type LocationsLocationpipelinesQuery = *mysql.ViewQuery[*LocationsLocationpipeline, LocationsLocationpipelineSlice] + +// locationsLocationpipelineR is where relationships are stored. +type locationsLocationpipelineR struct { + LocationLocationsLocation *LocationsLocation // locations_locationpi_location_id_1bff2f57_fk_locations + PipelineLocationsPipeline *LocationsPipeline // locations_locationpi_pipeline_id_2ad721b4_fk_locations +} + +func buildLocationsLocationpipelineColumns(alias string) locationsLocationpipelineColumns { + return locationsLocationpipelineColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "location_id", "pipeline_id", + ).WithParent("locations_locationpipeline"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + LocationID: mysql.Quote(alias, "location_id"), + PipelineID: mysql.Quote(alias, "pipeline_id"), + } +} + +type locationsLocationpipelineColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + LocationID mysql.Expression + PipelineID mysql.Expression +} + +func (c locationsLocationpipelineColumns) Alias() string { + return c.tableAlias +} + +func (locationsLocationpipelineColumns) AliasedAs(alias string) locationsLocationpipelineColumns { + return buildLocationsLocationpipelineColumns(alias) +} + +// LocationsLocationpipelineSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsLocationpipelineSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + LocationID omit.Val[string] `db:"location_id" ` + PipelineID omit.Val[string] `db:"pipeline_id" ` +} + +func (s LocationsLocationpipelineSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.LocationID.IsValue() { + vals = append(vals, "location_id") + } + if s.PipelineID.IsValue() { + vals = append(vals, "pipeline_id") + } + return vals +} + +func (s LocationsLocationpipelineSetter) Overwrite(t *LocationsLocationpipeline) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.LocationID.IsValue() { + t.LocationID = s.LocationID.MustGet() + } + if s.PipelineID.IsValue() { + t.PipelineID = s.PipelineID.MustGet() + } +} + +func (s *LocationsLocationpipelineSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocationpipelines.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.LocationID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.LocationID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.PipelineID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PipelineID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsLocationpipelineSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_locationpipeline")...) +} + +func (s LocationsLocationpipelineSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.LocationID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "location_id")...), + mysql.Arg(s.LocationID), + }}) + } + + if s.PipelineID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "pipeline_id")...), + mysql.Arg(s.PipelineID), + }}) + } + + return exprs +} + +// FindLocationsLocationpipeline retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsLocationpipeline(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsLocationpipeline, error) { + if len(cols) == 0 { + return LocationsLocationpipelines.Query( + sm.Where(LocationsLocationpipelines.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsLocationpipelines.Query( + sm.Where(LocationsLocationpipelines.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsLocationpipelines.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsLocationpipelineExists checks the presence of a single record by primary key +func LocationsLocationpipelineExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsLocationpipelines.Query( + sm.Where(LocationsLocationpipelines.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsLocationpipeline is retrieved from the database +func (o *LocationsLocationpipeline) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLocationpipelines.AfterSelectHooks.RunHooks(ctx, exec, LocationsLocationpipelineSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsLocationpipelines.AfterInsertHooks.RunHooks(ctx, exec, LocationsLocationpipelineSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsLocationpipelines.AfterUpdateHooks.RunHooks(ctx, exec, LocationsLocationpipelineSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsLocationpipelines.AfterDeleteHooks.RunHooks(ctx, exec, LocationsLocationpipelineSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsLocationpipeline +func (o *LocationsLocationpipeline) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsLocationpipeline) pkEQ() dialect.Expression { + return mysql.Quote("locations_locationpipeline", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsLocationpipeline +func (o *LocationsLocationpipeline) Update(ctx context.Context, exec bob.Executor, s *LocationsLocationpipelineSetter) error { + _, err := LocationsLocationpipelines.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsLocationpipeline record with an executor +func (o *LocationsLocationpipeline) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsLocationpipelines.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsLocationpipeline using the executor +func (o *LocationsLocationpipeline) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsLocationpipelines.Query( + sm.Where(LocationsLocationpipelines.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsLocationpipelineSlice is retrieved from the database +func (o LocationsLocationpipelineSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLocationpipelines.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsLocationpipelines.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsLocationpipelines.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsLocationpipelines.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsLocationpipelineSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_locationpipeline", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsLocationpipelineSlice) copyMatchingRows(from ...*LocationsLocationpipeline) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsLocationpipelineSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocationpipelines.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLocationpipeline: + o.copyMatchingRows(retrieved) + case []*LocationsLocationpipeline: + o.copyMatchingRows(retrieved...) + case LocationsLocationpipelineSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLocationpipeline or a slice of LocationsLocationpipeline + // then run the AfterUpdateHooks on the slice + _, err = LocationsLocationpipelines.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsLocationpipelineSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocationpipelines.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLocationpipeline: + o.copyMatchingRows(retrieved) + case []*LocationsLocationpipeline: + o.copyMatchingRows(retrieved...) + case LocationsLocationpipelineSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLocationpipeline or a slice of LocationsLocationpipeline + // then run the AfterDeleteHooks on the slice + _, err = LocationsLocationpipelines.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsLocationpipelineSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsLocationpipelineSetter) error { + _, err := LocationsLocationpipelines.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsLocationpipelineSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsLocationpipelines.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsLocationpipelineSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsLocationpipelines.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// LocationLocationsLocation starts a query for related objects on locations_location +func (o *LocationsLocationpipeline) LocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + return LocationsLocations.Query(append(mods, + sm.Where(LocationsLocations.Columns.UUID.EQ(mysql.Arg(o.LocationID))), + )...) +} + +func (os LocationsLocationpipelineSlice) LocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.LocationID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocations.Query(append(mods, + sm.Where(mysql.Group(LocationsLocations.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +// PipelineLocationsPipeline starts a query for related objects on locations_pipeline +func (o *LocationsLocationpipeline) PipelineLocationsPipeline(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPipelinesQuery { + return LocationsPipelines.Query(append(mods, + sm.Where(LocationsPipelines.Columns.UUID.EQ(mysql.Arg(o.PipelineID))), + )...) +} + +func (os LocationsLocationpipelineSlice) PipelineLocationsPipeline(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPipelinesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PipelineID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPipelines.Query(append(mods, + sm.Where(mysql.Group(LocationsPipelines.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsLocationpipelineLocationLocationsLocation0(ctx context.Context, exec bob.Executor, count int, locationsLocationpipeline0 *LocationsLocationpipeline, locationsLocation1 *LocationsLocation) (*LocationsLocationpipeline, error) { + setter := &LocationsLocationpipelineSetter{ + LocationID: omit.From(locationsLocation1.UUID), + } + + err := locationsLocationpipeline0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationpipelineLocationLocationsLocation0: %w", err) + } + + return locationsLocationpipeline0, nil +} + +func (locationsLocationpipeline0 *LocationsLocationpipeline) InsertLocationLocationsLocation(ctx context.Context, exec bob.Executor, related *LocationsLocationSetter) error { + var err error + + locationsLocation1, err := LocationsLocations.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsLocationpipelineLocationLocationsLocation0(ctx, exec, 1, locationsLocationpipeline0, locationsLocation1) + if err != nil { + return err + } + + locationsLocationpipeline0.R.LocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.LocationLocationsLocationpipelines = append(locationsLocation1.R.LocationLocationsLocationpipelines, locationsLocationpipeline0) + + return nil +} + +func (locationsLocationpipeline0 *LocationsLocationpipeline) AttachLocationLocationsLocation(ctx context.Context, exec bob.Executor, locationsLocation1 *LocationsLocation) error { + var err error + + _, err = attachLocationsLocationpipelineLocationLocationsLocation0(ctx, exec, 1, locationsLocationpipeline0, locationsLocation1) + if err != nil { + return err + } + + locationsLocationpipeline0.R.LocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.LocationLocationsLocationpipelines = append(locationsLocation1.R.LocationLocationsLocationpipelines, locationsLocationpipeline0) + + return nil +} + +func attachLocationsLocationpipelinePipelineLocationsPipeline0(ctx context.Context, exec bob.Executor, count int, locationsLocationpipeline0 *LocationsLocationpipeline, locationsPipeline1 *LocationsPipeline) (*LocationsLocationpipeline, error) { + setter := &LocationsLocationpipelineSetter{ + PipelineID: omit.From(locationsPipeline1.UUID), + } + + err := locationsLocationpipeline0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationpipelinePipelineLocationsPipeline0: %w", err) + } + + return locationsLocationpipeline0, nil +} + +func (locationsLocationpipeline0 *LocationsLocationpipeline) InsertPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, related *LocationsPipelineSetter) error { + var err error + + locationsPipeline1, err := LocationsPipelines.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsLocationpipelinePipelineLocationsPipeline0(ctx, exec, 1, locationsLocationpipeline0, locationsPipeline1) + if err != nil { + return err + } + + locationsLocationpipeline0.R.PipelineLocationsPipeline = locationsPipeline1 + + locationsPipeline1.R.PipelineLocationsLocationpipelines = append(locationsPipeline1.R.PipelineLocationsLocationpipelines, locationsLocationpipeline0) + + return nil +} + +func (locationsLocationpipeline0 *LocationsLocationpipeline) AttachPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, locationsPipeline1 *LocationsPipeline) error { + var err error + + _, err = attachLocationsLocationpipelinePipelineLocationsPipeline0(ctx, exec, 1, locationsLocationpipeline0, locationsPipeline1) + if err != nil { + return err + } + + locationsLocationpipeline0.R.PipelineLocationsPipeline = locationsPipeline1 + + locationsPipeline1.R.PipelineLocationsLocationpipelines = append(locationsPipeline1.R.PipelineLocationsLocationpipelines, locationsLocationpipeline0) + + return nil +} + +type locationsLocationpipelineWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + LocationID mysql.WhereMod[Q, string] + PipelineID mysql.WhereMod[Q, string] +} + +func (locationsLocationpipelineWhere[Q]) AliasedAs(alias string) locationsLocationpipelineWhere[Q] { + return buildLocationsLocationpipelineWhere[Q](buildLocationsLocationpipelineColumns(alias)) +} + +func buildLocationsLocationpipelineWhere[Q mysql.Filterable](cols locationsLocationpipelineColumns) locationsLocationpipelineWhere[Q] { + return locationsLocationpipelineWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + LocationID: mysql.Where[Q, string](cols.LocationID), + PipelineID: mysql.Where[Q, string](cols.PipelineID), + } +} + +func (o *LocationsLocationpipeline) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "LocationLocationsLocation": + rel, ok := retrieved.(*LocationsLocation) + if !ok { + return fmt.Errorf("locationsLocationpipeline cannot load %T as %q", retrieved, name) + } + + o.R.LocationLocationsLocation = rel + + if rel != nil { + rel.R.LocationLocationsLocationpipelines = LocationsLocationpipelineSlice{o} + } + return nil + case "PipelineLocationsPipeline": + rel, ok := retrieved.(*LocationsPipeline) + if !ok { + return fmt.Errorf("locationsLocationpipeline cannot load %T as %q", retrieved, name) + } + + o.R.PipelineLocationsPipeline = rel + + if rel != nil { + rel.R.PipelineLocationsLocationpipelines = LocationsLocationpipelineSlice{o} + } + return nil + default: + return fmt.Errorf("locationsLocationpipeline has no relationship %q", name) + } +} + +type locationsLocationpipelinePreloader struct { + LocationLocationsLocation func(...mysql.PreloadOption) mysql.Preloader + PipelineLocationsPipeline func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsLocationpipelinePreloader() locationsLocationpipelinePreloader { + return locationsLocationpipelinePreloader{ + LocationLocationsLocation: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsLocation, LocationsLocationSlice](mysql.PreloadRel{ + Name: "LocationLocationsLocation", + Sides: []mysql.PreloadSide{ + { + From: LocationsLocationpipelines, + To: LocationsLocations, + FromColumns: []string{"location_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsLocations.Columns.Names(), opts...) + }, + PipelineLocationsPipeline: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPipeline, LocationsPipelineSlice](mysql.PreloadRel{ + Name: "PipelineLocationsPipeline", + Sides: []mysql.PreloadSide{ + { + From: LocationsLocationpipelines, + To: LocationsPipelines, + FromColumns: []string{"pipeline_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsPipelines.Columns.Names(), opts...) + }, + } +} + +type locationsLocationpipelineThenLoader[Q orm.Loadable] struct { + LocationLocationsLocation func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PipelineLocationsPipeline func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsLocationpipelineThenLoader[Q orm.Loadable]() locationsLocationpipelineThenLoader[Q] { + type LocationLocationsLocationLoadInterface interface { + LoadLocationLocationsLocation(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PipelineLocationsPipelineLoadInterface interface { + LoadPipelineLocationsPipeline(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsLocationpipelineThenLoader[Q]{ + LocationLocationsLocation: thenLoadBuilder[Q]( + "LocationLocationsLocation", + func(ctx context.Context, exec bob.Executor, retrieved LocationLocationsLocationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadLocationLocationsLocation(ctx, exec, mods...) + }, + ), + PipelineLocationsPipeline: thenLoadBuilder[Q]( + "PipelineLocationsPipeline", + func(ctx context.Context, exec bob.Executor, retrieved PipelineLocationsPipelineLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPipelineLocationsPipeline(ctx, exec, mods...) + }, + ), + } +} + +// LoadLocationLocationsLocation loads the locationsLocationpipeline's LocationLocationsLocation into the .R struct +func (o *LocationsLocationpipeline) LoadLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.LocationLocationsLocation = nil + + related, err := o.LocationLocationsLocation(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.LocationLocationsLocationpipelines = LocationsLocationpipelineSlice{o} + + o.R.LocationLocationsLocation = related + return nil +} + +// LoadLocationLocationsLocation loads the locationsLocationpipeline's LocationLocationsLocation into the .R struct +func (os LocationsLocationpipelineSlice) LoadLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocations, err := os.LocationLocationsLocation(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocations { + + if !(o.LocationID == rel.UUID) { + continue + } + + rel.R.LocationLocationsLocationpipelines = append(rel.R.LocationLocationsLocationpipelines, o) + + o.R.LocationLocationsLocation = rel + break + } + } + + return nil +} + +// LoadPipelineLocationsPipeline loads the locationsLocationpipeline's PipelineLocationsPipeline into the .R struct +func (o *LocationsLocationpipeline) LoadPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PipelineLocationsPipeline = nil + + related, err := o.PipelineLocationsPipeline(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PipelineLocationsLocationpipelines = LocationsLocationpipelineSlice{o} + + o.R.PipelineLocationsPipeline = related + return nil +} + +// LoadPipelineLocationsPipeline loads the locationsLocationpipeline's PipelineLocationsPipeline into the .R struct +func (os LocationsLocationpipelineSlice) LoadPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPipelines, err := os.PipelineLocationsPipeline(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPipelines { + + if !(o.PipelineID == rel.UUID) { + continue + } + + rel.R.PipelineLocationsLocationpipelines = append(rel.R.PipelineLocationsLocationpipelines, o) + + o.R.PipelineLocationsPipeline = rel + break + } + } + + return nil +} + +type locationsLocationpipelineJoins[Q dialect.Joinable] struct { + typ string + LocationLocationsLocation modAs[Q, locationsLocationColumns] + PipelineLocationsPipeline modAs[Q, locationsPipelineColumns] +} + +func (j locationsLocationpipelineJoins[Q]) aliasedAs(alias string) locationsLocationpipelineJoins[Q] { + return buildLocationsLocationpipelineJoins[Q](buildLocationsLocationpipelineColumns(alias), j.typ) +} + +func buildLocationsLocationpipelineJoins[Q dialect.Joinable](cols locationsLocationpipelineColumns, typ string) locationsLocationpipelineJoins[Q] { + return locationsLocationpipelineJoins[Q]{ + typ: typ, + LocationLocationsLocation: modAs[Q, locationsLocationColumns]{ + c: LocationsLocations.Columns, + f: func(to locationsLocationColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocations.Name().As(to.Alias())).On( + to.UUID.EQ(cols.LocationID), + )) + } + + return mods + }, + }, + PipelineLocationsPipeline: modAs[Q, locationsPipelineColumns]{ + c: LocationsPipelines.Columns, + f: func(to locationsPipelineColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPipelines.Name().As(to.Alias())).On( + to.UUID.EQ(cols.PipelineID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_lockssomatic.bob.go b/database/mcp/models/locations_lockssomatic.bob.go new file mode 100644 index 0000000..11968c0 --- /dev/null +++ b/database/mcp/models/locations_lockssomatic.bob.go @@ -0,0 +1,762 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsLockssomatic is an object representing the database table. +type LocationsLockssomatic struct { + ID int32 `db:"id,pk,autoincr" ` + AuSize null.Val[int64] `db:"au_size" ` + SDIri string `db:"sd_iri" ` + CollectionIri null.Val[string] `db:"collection_iri" ` + ContentProviderID string `db:"content_provider_id" ` + ExternalDomain string `db:"external_domain" ` + ChecksumType null.Val[string] `db:"checksum_type" ` + KeepLocal bool `db:"keep_local" ` + SpaceID string `db:"space_id" ` + + R locationsLockssomaticR `db:"-" ` +} + +// LocationsLockssomaticSlice is an alias for a slice of pointers to LocationsLockssomatic. +// This should almost always be used instead of []*LocationsLockssomatic. +type LocationsLockssomaticSlice []*LocationsLockssomatic + +// LocationsLockssomatics contains methods to work with the locations_lockssomatic table +var LocationsLockssomatics = mysql.NewTablex[*LocationsLockssomatic, LocationsLockssomaticSlice, *LocationsLockssomaticSetter]("locations_lockssomatic", buildLocationsLockssomaticColumns("locations_lockssomatic"), []string{"id"}, []string{"space_id"}) + +// LocationsLockssomaticsQuery is a query on the locations_lockssomatic table +type LocationsLockssomaticsQuery = *mysql.ViewQuery[*LocationsLockssomatic, LocationsLockssomaticSlice] + +// locationsLockssomaticR is where relationships are stored. +type locationsLockssomaticR struct { + SpaceLocationsSpace *LocationsSpace // locations_lockssomatic_space_id_cc6a3cd6_fk_locations_space_uuid +} + +func buildLocationsLockssomaticColumns(alias string) locationsLockssomaticColumns { + return locationsLockssomaticColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "au_size", "sd_iri", "collection_iri", "content_provider_id", "external_domain", "checksum_type", "keep_local", "space_id", + ).WithParent("locations_lockssomatic"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + AuSize: mysql.Quote(alias, "au_size"), + SDIri: mysql.Quote(alias, "sd_iri"), + CollectionIri: mysql.Quote(alias, "collection_iri"), + ContentProviderID: mysql.Quote(alias, "content_provider_id"), + ExternalDomain: mysql.Quote(alias, "external_domain"), + ChecksumType: mysql.Quote(alias, "checksum_type"), + KeepLocal: mysql.Quote(alias, "keep_local"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsLockssomaticColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + AuSize mysql.Expression + SDIri mysql.Expression + CollectionIri mysql.Expression + ContentProviderID mysql.Expression + ExternalDomain mysql.Expression + ChecksumType mysql.Expression + KeepLocal mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsLockssomaticColumns) Alias() string { + return c.tableAlias +} + +func (locationsLockssomaticColumns) AliasedAs(alias string) locationsLockssomaticColumns { + return buildLocationsLockssomaticColumns(alias) +} + +// LocationsLockssomaticSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsLockssomaticSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + AuSize omitnull.Val[int64] `db:"au_size" ` + SDIri omit.Val[string] `db:"sd_iri" ` + CollectionIri omitnull.Val[string] `db:"collection_iri" ` + ContentProviderID omit.Val[string] `db:"content_provider_id" ` + ExternalDomain omit.Val[string] `db:"external_domain" ` + ChecksumType omitnull.Val[string] `db:"checksum_type" ` + KeepLocal omit.Val[bool] `db:"keep_local" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsLockssomaticSetter) SetColumns() []string { + vals := make([]string, 0, 9) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if !s.AuSize.IsUnset() { + vals = append(vals, "au_size") + } + if s.SDIri.IsValue() { + vals = append(vals, "sd_iri") + } + if !s.CollectionIri.IsUnset() { + vals = append(vals, "collection_iri") + } + if s.ContentProviderID.IsValue() { + vals = append(vals, "content_provider_id") + } + if s.ExternalDomain.IsValue() { + vals = append(vals, "external_domain") + } + if !s.ChecksumType.IsUnset() { + vals = append(vals, "checksum_type") + } + if s.KeepLocal.IsValue() { + vals = append(vals, "keep_local") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsLockssomaticSetter) Overwrite(t *LocationsLockssomatic) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if !s.AuSize.IsUnset() { + t.AuSize = s.AuSize.MustGetNull() + } + if s.SDIri.IsValue() { + t.SDIri = s.SDIri.MustGet() + } + if !s.CollectionIri.IsUnset() { + t.CollectionIri = s.CollectionIri.MustGetNull() + } + if s.ContentProviderID.IsValue() { + t.ContentProviderID = s.ContentProviderID.MustGet() + } + if s.ExternalDomain.IsValue() { + t.ExternalDomain = s.ExternalDomain.MustGet() + } + if !s.ChecksumType.IsUnset() { + t.ChecksumType = s.ChecksumType.MustGetNull() + } + if s.KeepLocal.IsValue() { + t.KeepLocal = s.KeepLocal.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsLockssomaticSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLockssomatics.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.AuSize.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AuSize.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SDIri.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SDIri.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.CollectionIri.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.CollectionIri.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ContentProviderID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ContentProviderID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ExternalDomain.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ExternalDomain.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.ChecksumType.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ChecksumType.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.KeepLocal.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.KeepLocal.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsLockssomaticSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_lockssomatic")...) +} + +func (s LocationsLockssomaticSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 9) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if !s.AuSize.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "au_size")...), + mysql.Arg(s.AuSize), + }}) + } + + if s.SDIri.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "sd_iri")...), + mysql.Arg(s.SDIri), + }}) + } + + if !s.CollectionIri.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "collection_iri")...), + mysql.Arg(s.CollectionIri), + }}) + } + + if s.ContentProviderID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "content_provider_id")...), + mysql.Arg(s.ContentProviderID), + }}) + } + + if s.ExternalDomain.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "external_domain")...), + mysql.Arg(s.ExternalDomain), + }}) + } + + if !s.ChecksumType.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "checksum_type")...), + mysql.Arg(s.ChecksumType), + }}) + } + + if s.KeepLocal.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "keep_local")...), + mysql.Arg(s.KeepLocal), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsLockssomatic retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsLockssomatic(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsLockssomatic, error) { + if len(cols) == 0 { + return LocationsLockssomatics.Query( + sm.Where(LocationsLockssomatics.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsLockssomatics.Query( + sm.Where(LocationsLockssomatics.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsLockssomatics.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsLockssomaticExists checks the presence of a single record by primary key +func LocationsLockssomaticExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsLockssomatics.Query( + sm.Where(LocationsLockssomatics.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsLockssomatic is retrieved from the database +func (o *LocationsLockssomatic) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLockssomatics.AfterSelectHooks.RunHooks(ctx, exec, LocationsLockssomaticSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsLockssomatics.AfterInsertHooks.RunHooks(ctx, exec, LocationsLockssomaticSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsLockssomatics.AfterUpdateHooks.RunHooks(ctx, exec, LocationsLockssomaticSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsLockssomatics.AfterDeleteHooks.RunHooks(ctx, exec, LocationsLockssomaticSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsLockssomatic +func (o *LocationsLockssomatic) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsLockssomatic) pkEQ() dialect.Expression { + return mysql.Quote("locations_lockssomatic", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsLockssomatic +func (o *LocationsLockssomatic) Update(ctx context.Context, exec bob.Executor, s *LocationsLockssomaticSetter) error { + _, err := LocationsLockssomatics.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsLockssomatic record with an executor +func (o *LocationsLockssomatic) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsLockssomatics.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsLockssomatic using the executor +func (o *LocationsLockssomatic) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsLockssomatics.Query( + sm.Where(LocationsLockssomatics.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsLockssomaticSlice is retrieved from the database +func (o LocationsLockssomaticSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLockssomatics.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsLockssomatics.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsLockssomatics.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsLockssomatics.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsLockssomaticSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_lockssomatic", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsLockssomaticSlice) copyMatchingRows(from ...*LocationsLockssomatic) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsLockssomaticSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLockssomatics.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLockssomatic: + o.copyMatchingRows(retrieved) + case []*LocationsLockssomatic: + o.copyMatchingRows(retrieved...) + case LocationsLockssomaticSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLockssomatic or a slice of LocationsLockssomatic + // then run the AfterUpdateHooks on the slice + _, err = LocationsLockssomatics.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsLockssomaticSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLockssomatics.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLockssomatic: + o.copyMatchingRows(retrieved) + case []*LocationsLockssomatic: + o.copyMatchingRows(retrieved...) + case LocationsLockssomaticSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLockssomatic or a slice of LocationsLockssomatic + // then run the AfterDeleteHooks on the slice + _, err = LocationsLockssomatics.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsLockssomaticSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsLockssomaticSetter) error { + _, err := LocationsLockssomatics.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsLockssomaticSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsLockssomatics.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsLockssomaticSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsLockssomatics.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsLockssomatic) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsLockssomaticSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsLockssomaticSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsLockssomatic0 *LocationsLockssomatic, locationsSpace1 *LocationsSpace) (*LocationsLockssomatic, error) { + setter := &LocationsLockssomaticSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsLockssomatic0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLockssomaticSpaceLocationsSpace0: %w", err) + } + + return locationsLockssomatic0, nil +} + +func (locationsLockssomatic0 *LocationsLockssomatic) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsLockssomaticSpaceLocationsSpace0(ctx, exec, 1, locationsLockssomatic0, locationsSpace1) + if err != nil { + return err + } + + locationsLockssomatic0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsLockssomatic = locationsLockssomatic0 + + return nil +} + +func (locationsLockssomatic0 *LocationsLockssomatic) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsLockssomaticSpaceLocationsSpace0(ctx, exec, 1, locationsLockssomatic0, locationsSpace1) + if err != nil { + return err + } + + locationsLockssomatic0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsLockssomatic = locationsLockssomatic0 + + return nil +} + +type locationsLockssomaticWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + AuSize mysql.WhereNullMod[Q, int64] + SDIri mysql.WhereMod[Q, string] + CollectionIri mysql.WhereNullMod[Q, string] + ContentProviderID mysql.WhereMod[Q, string] + ExternalDomain mysql.WhereMod[Q, string] + ChecksumType mysql.WhereNullMod[Q, string] + KeepLocal mysql.WhereMod[Q, bool] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsLockssomaticWhere[Q]) AliasedAs(alias string) locationsLockssomaticWhere[Q] { + return buildLocationsLockssomaticWhere[Q](buildLocationsLockssomaticColumns(alias)) +} + +func buildLocationsLockssomaticWhere[Q mysql.Filterable](cols locationsLockssomaticColumns) locationsLockssomaticWhere[Q] { + return locationsLockssomaticWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + AuSize: mysql.WhereNull[Q, int64](cols.AuSize), + SDIri: mysql.Where[Q, string](cols.SDIri), + CollectionIri: mysql.WhereNull[Q, string](cols.CollectionIri), + ContentProviderID: mysql.Where[Q, string](cols.ContentProviderID), + ExternalDomain: mysql.Where[Q, string](cols.ExternalDomain), + ChecksumType: mysql.WhereNull[Q, string](cols.ChecksumType), + KeepLocal: mysql.Where[Q, bool](cols.KeepLocal), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsLockssomatic) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsLockssomatic cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsLockssomatic = o + } + return nil + default: + return fmt.Errorf("locationsLockssomatic has no relationship %q", name) + } +} + +type locationsLockssomaticPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsLockssomaticPreloader() locationsLockssomaticPreloader { + return locationsLockssomaticPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsLockssomatics, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsLockssomaticThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsLockssomaticThenLoader[Q orm.Loadable]() locationsLockssomaticThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsLockssomaticThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsLockssomatic's SpaceLocationsSpace into the .R struct +func (o *LocationsLockssomatic) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsLockssomatic = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsLockssomatic's SpaceLocationsSpace into the .R struct +func (os LocationsLockssomaticSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsLockssomatic = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsLockssomaticJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsLockssomaticJoins[Q]) aliasedAs(alias string) locationsLockssomaticJoins[Q] { + return buildLocationsLockssomaticJoins[Q](buildLocationsLockssomaticColumns(alias), j.typ) +} + +func buildLocationsLockssomaticJoins[Q dialect.Joinable](cols locationsLockssomaticColumns, typ string) locationsLockssomaticJoins[Q] { + return locationsLockssomaticJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_nfs.bob.go b/database/mcp/models/locations_nfs.bob.go new file mode 100644 index 0000000..d5cc96d --- /dev/null +++ b/database/mcp/models/locations_nfs.bob.go @@ -0,0 +1,688 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsNF is an object representing the database table. +type LocationsNF struct { + ID int32 `db:"id,pk,autoincr" ` + RemoteName string `db:"remote_name" ` + RemotePath string `db:"remote_path" ` + Version string `db:"version" ` + ManuallyMounted bool `db:"manually_mounted" ` + SpaceID string `db:"space_id" ` + + R locationsNFR `db:"-" ` +} + +// LocationsNFSlice is an alias for a slice of pointers to LocationsNF. +// This should almost always be used instead of []*LocationsNF. +type LocationsNFSlice []*LocationsNF + +// LocationsNFS contains methods to work with the locations_nfs table +var LocationsNFS = mysql.NewTablex[*LocationsNF, LocationsNFSlice, *LocationsNFSetter]("locations_nfs", buildLocationsNFColumns("locations_nfs"), []string{"id"}, []string{"space_id"}) + +// LocationsNFSQuery is a query on the locations_nfs table +type LocationsNFSQuery = *mysql.ViewQuery[*LocationsNF, LocationsNFSlice] + +// locationsNFR is where relationships are stored. +type locationsNFR struct { + SpaceLocationsSpace *LocationsSpace // locations_nfs_space_id_34913c3b_fk_locations_space_uuid +} + +func buildLocationsNFColumns(alias string) locationsNFColumns { + return locationsNFColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "remote_name", "remote_path", "version", "manually_mounted", "space_id", + ).WithParent("locations_nfs"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + RemoteName: mysql.Quote(alias, "remote_name"), + RemotePath: mysql.Quote(alias, "remote_path"), + Version: mysql.Quote(alias, "version"), + ManuallyMounted: mysql.Quote(alias, "manually_mounted"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsNFColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + RemoteName mysql.Expression + RemotePath mysql.Expression + Version mysql.Expression + ManuallyMounted mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsNFColumns) Alias() string { + return c.tableAlias +} + +func (locationsNFColumns) AliasedAs(alias string) locationsNFColumns { + return buildLocationsNFColumns(alias) +} + +// LocationsNFSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsNFSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + RemoteName omit.Val[string] `db:"remote_name" ` + RemotePath omit.Val[string] `db:"remote_path" ` + Version omit.Val[string] `db:"version" ` + ManuallyMounted omit.Val[bool] `db:"manually_mounted" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsNFSetter) SetColumns() []string { + vals := make([]string, 0, 6) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.RemoteName.IsValue() { + vals = append(vals, "remote_name") + } + if s.RemotePath.IsValue() { + vals = append(vals, "remote_path") + } + if s.Version.IsValue() { + vals = append(vals, "version") + } + if s.ManuallyMounted.IsValue() { + vals = append(vals, "manually_mounted") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsNFSetter) Overwrite(t *LocationsNF) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.RemoteName.IsValue() { + t.RemoteName = s.RemoteName.MustGet() + } + if s.RemotePath.IsValue() { + t.RemotePath = s.RemotePath.MustGet() + } + if s.Version.IsValue() { + t.Version = s.Version.MustGet() + } + if s.ManuallyMounted.IsValue() { + t.ManuallyMounted = s.ManuallyMounted.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsNFSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsNFS.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.RemoteName.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RemoteName.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.RemotePath.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RemotePath.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Version.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Version.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ManuallyMounted.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ManuallyMounted.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsNFSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_nfs")...) +} + +func (s LocationsNFSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 6) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.RemoteName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "remote_name")...), + mysql.Arg(s.RemoteName), + }}) + } + + if s.RemotePath.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "remote_path")...), + mysql.Arg(s.RemotePath), + }}) + } + + if s.Version.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "version")...), + mysql.Arg(s.Version), + }}) + } + + if s.ManuallyMounted.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "manually_mounted")...), + mysql.Arg(s.ManuallyMounted), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsNF retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsNF(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsNF, error) { + if len(cols) == 0 { + return LocationsNFS.Query( + sm.Where(LocationsNFS.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsNFS.Query( + sm.Where(LocationsNFS.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsNFS.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsNFExists checks the presence of a single record by primary key +func LocationsNFExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsNFS.Query( + sm.Where(LocationsNFS.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsNF is retrieved from the database +func (o *LocationsNF) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsNFS.AfterSelectHooks.RunHooks(ctx, exec, LocationsNFSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsNFS.AfterInsertHooks.RunHooks(ctx, exec, LocationsNFSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsNFS.AfterUpdateHooks.RunHooks(ctx, exec, LocationsNFSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsNFS.AfterDeleteHooks.RunHooks(ctx, exec, LocationsNFSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsNF +func (o *LocationsNF) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsNF) pkEQ() dialect.Expression { + return mysql.Quote("locations_nfs", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsNF +func (o *LocationsNF) Update(ctx context.Context, exec bob.Executor, s *LocationsNFSetter) error { + _, err := LocationsNFS.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsNF record with an executor +func (o *LocationsNF) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsNFS.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsNF using the executor +func (o *LocationsNF) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsNFS.Query( + sm.Where(LocationsNFS.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsNFSlice is retrieved from the database +func (o LocationsNFSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsNFS.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsNFS.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsNFS.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsNFS.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsNFSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_nfs", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsNFSlice) copyMatchingRows(from ...*LocationsNF) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsNFSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsNFS.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsNF: + o.copyMatchingRows(retrieved) + case []*LocationsNF: + o.copyMatchingRows(retrieved...) + case LocationsNFSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsNF or a slice of LocationsNF + // then run the AfterUpdateHooks on the slice + _, err = LocationsNFS.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsNFSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsNFS.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsNF: + o.copyMatchingRows(retrieved) + case []*LocationsNF: + o.copyMatchingRows(retrieved...) + case LocationsNFSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsNF or a slice of LocationsNF + // then run the AfterDeleteHooks on the slice + _, err = LocationsNFS.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsNFSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsNFSetter) error { + _, err := LocationsNFS.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsNFSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsNFS.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsNFSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsNFS.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsNF) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsNFSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsNFSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsNF0 *LocationsNF, locationsSpace1 *LocationsSpace) (*LocationsNF, error) { + setter := &LocationsNFSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsNF0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsNFSpaceLocationsSpace0: %w", err) + } + + return locationsNF0, nil +} + +func (locationsNF0 *LocationsNF) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsNFSpaceLocationsSpace0(ctx, exec, 1, locationsNF0, locationsSpace1) + if err != nil { + return err + } + + locationsNF0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsNF = locationsNF0 + + return nil +} + +func (locationsNF0 *LocationsNF) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsNFSpaceLocationsSpace0(ctx, exec, 1, locationsNF0, locationsSpace1) + if err != nil { + return err + } + + locationsNF0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsNF = locationsNF0 + + return nil +} + +type locationsNFWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + RemoteName mysql.WhereMod[Q, string] + RemotePath mysql.WhereMod[Q, string] + Version mysql.WhereMod[Q, string] + ManuallyMounted mysql.WhereMod[Q, bool] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsNFWhere[Q]) AliasedAs(alias string) locationsNFWhere[Q] { + return buildLocationsNFWhere[Q](buildLocationsNFColumns(alias)) +} + +func buildLocationsNFWhere[Q mysql.Filterable](cols locationsNFColumns) locationsNFWhere[Q] { + return locationsNFWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + RemoteName: mysql.Where[Q, string](cols.RemoteName), + RemotePath: mysql.Where[Q, string](cols.RemotePath), + Version: mysql.Where[Q, string](cols.Version), + ManuallyMounted: mysql.Where[Q, bool](cols.ManuallyMounted), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsNF) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsNF cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsNF = o + } + return nil + default: + return fmt.Errorf("locationsNF has no relationship %q", name) + } +} + +type locationsNFPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsNFPreloader() locationsNFPreloader { + return locationsNFPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsNFS, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsNFThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsNFThenLoader[Q orm.Loadable]() locationsNFThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsNFThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsNF's SpaceLocationsSpace into the .R struct +func (o *LocationsNF) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsNF = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsNF's SpaceLocationsSpace into the .R struct +func (os LocationsNFSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsNF = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsNFJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsNFJoins[Q]) aliasedAs(alias string) locationsNFJoins[Q] { + return buildLocationsNFJoins[Q](buildLocationsNFColumns(alias), j.typ) +} + +func buildLocationsNFJoins[Q dialect.Joinable](cols locationsNFColumns, typ string) locationsNFJoins[Q] { + return locationsNFJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_offlinereplicastaging.bob.go b/database/mcp/models/locations_offlinereplicastaging.bob.go new file mode 100644 index 0000000..cc054ef --- /dev/null +++ b/database/mcp/models/locations_offlinereplicastaging.bob.go @@ -0,0 +1,592 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsOfflinereplicastaging is an object representing the database table. +type LocationsOfflinereplicastaging struct { + ID int32 `db:"id,pk,autoincr" ` + SpaceID string `db:"space_id" ` + + R locationsOfflinereplicastagingR `db:"-" ` +} + +// LocationsOfflinereplicastagingSlice is an alias for a slice of pointers to LocationsOfflinereplicastaging. +// This should almost always be used instead of []*LocationsOfflinereplicastaging. +type LocationsOfflinereplicastagingSlice []*LocationsOfflinereplicastaging + +// LocationsOfflinereplicastagings contains methods to work with the locations_offlinereplicastaging table +var LocationsOfflinereplicastagings = mysql.NewTablex[*LocationsOfflinereplicastaging, LocationsOfflinereplicastagingSlice, *LocationsOfflinereplicastagingSetter]("locations_offlinereplicastaging", buildLocationsOfflinereplicastagingColumns("locations_offlinereplicastaging"), []string{"id"}, []string{"space_id"}) + +// LocationsOfflinereplicastagingsQuery is a query on the locations_offlinereplicastaging table +type LocationsOfflinereplicastagingsQuery = *mysql.ViewQuery[*LocationsOfflinereplicastaging, LocationsOfflinereplicastagingSlice] + +// locationsOfflinereplicastagingR is where relationships are stored. +type locationsOfflinereplicastagingR struct { + SpaceLocationsSpace *LocationsSpace // locations_offlinerep_space_id_2a8d7578_fk_locations +} + +func buildLocationsOfflinereplicastagingColumns(alias string) locationsOfflinereplicastagingColumns { + return locationsOfflinereplicastagingColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "space_id", + ).WithParent("locations_offlinereplicastaging"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsOfflinereplicastagingColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsOfflinereplicastagingColumns) Alias() string { + return c.tableAlias +} + +func (locationsOfflinereplicastagingColumns) AliasedAs(alias string) locationsOfflinereplicastagingColumns { + return buildLocationsOfflinereplicastagingColumns(alias) +} + +// LocationsOfflinereplicastagingSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsOfflinereplicastagingSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsOfflinereplicastagingSetter) SetColumns() []string { + vals := make([]string, 0, 2) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsOfflinereplicastagingSetter) Overwrite(t *LocationsOfflinereplicastaging) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsOfflinereplicastagingSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsOfflinereplicastagings.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsOfflinereplicastagingSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_offlinereplicastaging")...) +} + +func (s LocationsOfflinereplicastagingSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 2) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsOfflinereplicastaging retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsOfflinereplicastaging(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsOfflinereplicastaging, error) { + if len(cols) == 0 { + return LocationsOfflinereplicastagings.Query( + sm.Where(LocationsOfflinereplicastagings.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsOfflinereplicastagings.Query( + sm.Where(LocationsOfflinereplicastagings.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsOfflinereplicastagings.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsOfflinereplicastagingExists checks the presence of a single record by primary key +func LocationsOfflinereplicastagingExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsOfflinereplicastagings.Query( + sm.Where(LocationsOfflinereplicastagings.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsOfflinereplicastaging is retrieved from the database +func (o *LocationsOfflinereplicastaging) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsOfflinereplicastagings.AfterSelectHooks.RunHooks(ctx, exec, LocationsOfflinereplicastagingSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsOfflinereplicastagings.AfterInsertHooks.RunHooks(ctx, exec, LocationsOfflinereplicastagingSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsOfflinereplicastagings.AfterUpdateHooks.RunHooks(ctx, exec, LocationsOfflinereplicastagingSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsOfflinereplicastagings.AfterDeleteHooks.RunHooks(ctx, exec, LocationsOfflinereplicastagingSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsOfflinereplicastaging +func (o *LocationsOfflinereplicastaging) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsOfflinereplicastaging) pkEQ() dialect.Expression { + return mysql.Quote("locations_offlinereplicastaging", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsOfflinereplicastaging +func (o *LocationsOfflinereplicastaging) Update(ctx context.Context, exec bob.Executor, s *LocationsOfflinereplicastagingSetter) error { + _, err := LocationsOfflinereplicastagings.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsOfflinereplicastaging record with an executor +func (o *LocationsOfflinereplicastaging) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsOfflinereplicastagings.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsOfflinereplicastaging using the executor +func (o *LocationsOfflinereplicastaging) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsOfflinereplicastagings.Query( + sm.Where(LocationsOfflinereplicastagings.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsOfflinereplicastagingSlice is retrieved from the database +func (o LocationsOfflinereplicastagingSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsOfflinereplicastagings.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsOfflinereplicastagings.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsOfflinereplicastagings.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsOfflinereplicastagings.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsOfflinereplicastagingSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_offlinereplicastaging", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsOfflinereplicastagingSlice) copyMatchingRows(from ...*LocationsOfflinereplicastaging) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsOfflinereplicastagingSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsOfflinereplicastagings.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsOfflinereplicastaging: + o.copyMatchingRows(retrieved) + case []*LocationsOfflinereplicastaging: + o.copyMatchingRows(retrieved...) + case LocationsOfflinereplicastagingSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsOfflinereplicastaging or a slice of LocationsOfflinereplicastaging + // then run the AfterUpdateHooks on the slice + _, err = LocationsOfflinereplicastagings.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsOfflinereplicastagingSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsOfflinereplicastagings.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsOfflinereplicastaging: + o.copyMatchingRows(retrieved) + case []*LocationsOfflinereplicastaging: + o.copyMatchingRows(retrieved...) + case LocationsOfflinereplicastagingSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsOfflinereplicastaging or a slice of LocationsOfflinereplicastaging + // then run the AfterDeleteHooks on the slice + _, err = LocationsOfflinereplicastagings.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsOfflinereplicastagingSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsOfflinereplicastagingSetter) error { + _, err := LocationsOfflinereplicastagings.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsOfflinereplicastagingSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsOfflinereplicastagings.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsOfflinereplicastagingSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsOfflinereplicastagings.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsOfflinereplicastaging) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsOfflinereplicastagingSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsOfflinereplicastagingSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsOfflinereplicastaging0 *LocationsOfflinereplicastaging, locationsSpace1 *LocationsSpace) (*LocationsOfflinereplicastaging, error) { + setter := &LocationsOfflinereplicastagingSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsOfflinereplicastaging0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsOfflinereplicastagingSpaceLocationsSpace0: %w", err) + } + + return locationsOfflinereplicastaging0, nil +} + +func (locationsOfflinereplicastaging0 *LocationsOfflinereplicastaging) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsOfflinereplicastagingSpaceLocationsSpace0(ctx, exec, 1, locationsOfflinereplicastaging0, locationsSpace1) + if err != nil { + return err + } + + locationsOfflinereplicastaging0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsOfflinereplicastaging = locationsOfflinereplicastaging0 + + return nil +} + +func (locationsOfflinereplicastaging0 *LocationsOfflinereplicastaging) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsOfflinereplicastagingSpaceLocationsSpace0(ctx, exec, 1, locationsOfflinereplicastaging0, locationsSpace1) + if err != nil { + return err + } + + locationsOfflinereplicastaging0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsOfflinereplicastaging = locationsOfflinereplicastaging0 + + return nil +} + +type locationsOfflinereplicastagingWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsOfflinereplicastagingWhere[Q]) AliasedAs(alias string) locationsOfflinereplicastagingWhere[Q] { + return buildLocationsOfflinereplicastagingWhere[Q](buildLocationsOfflinereplicastagingColumns(alias)) +} + +func buildLocationsOfflinereplicastagingWhere[Q mysql.Filterable](cols locationsOfflinereplicastagingColumns) locationsOfflinereplicastagingWhere[Q] { + return locationsOfflinereplicastagingWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsOfflinereplicastaging) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsOfflinereplicastaging cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsOfflinereplicastaging = o + } + return nil + default: + return fmt.Errorf("locationsOfflinereplicastaging has no relationship %q", name) + } +} + +type locationsOfflinereplicastagingPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsOfflinereplicastagingPreloader() locationsOfflinereplicastagingPreloader { + return locationsOfflinereplicastagingPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsOfflinereplicastagings, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsOfflinereplicastagingThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsOfflinereplicastagingThenLoader[Q orm.Loadable]() locationsOfflinereplicastagingThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsOfflinereplicastagingThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsOfflinereplicastaging's SpaceLocationsSpace into the .R struct +func (o *LocationsOfflinereplicastaging) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsOfflinereplicastaging = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsOfflinereplicastaging's SpaceLocationsSpace into the .R struct +func (os LocationsOfflinereplicastagingSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsOfflinereplicastaging = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsOfflinereplicastagingJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsOfflinereplicastagingJoins[Q]) aliasedAs(alias string) locationsOfflinereplicastagingJoins[Q] { + return buildLocationsOfflinereplicastagingJoins[Q](buildLocationsOfflinereplicastagingColumns(alias), j.typ) +} + +func buildLocationsOfflinereplicastagingJoins[Q dialect.Joinable](cols locationsOfflinereplicastagingColumns, typ string) locationsOfflinereplicastagingJoins[Q] { + return locationsOfflinereplicastagingJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_package.bob.go b/database/mcp/models/locations_package.bob.go new file mode 100644 index 0000000..c1714d2 --- /dev/null +++ b/database/mcp/models/locations_package.bob.go @@ -0,0 +1,2799 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsPackage is an object representing the database table. +type LocationsPackage struct { + ID int32 `db:"id,pk,autoincr" ` + UUID string `db:"uuid" ` + CurrentPath string `db:"current_path" ` + PointerFilePath null.Val[string] `db:"pointer_file_path" ` + Size int64 `db:"size" ` + PackageType string `db:"package_type" ` + Status string `db:"status" ` + CurrentLocationID string `db:"current_location_id" ` + OriginPipelineID null.Val[string] `db:"origin_pipeline_id" ` + PointerFileLocationID null.Val[string] `db:"pointer_file_location_id" ` + MiscAttributes null.Val[string] `db:"misc_attributes" ` + Description null.Val[string] `db:"description" ` + EncryptionKeyFingerprint null.Val[string] `db:"encryption_key_fingerprint" ` + ReplicatedPackageID null.Val[string] `db:"replicated_package_id" ` + StoredDate null.Val[time.Time] `db:"stored_date" ` + Checksum null.Val[string] `db:"checksum" ` + ChecksumAlgorithm null.Val[string] `db:"checksum_algorithm" ` + + R locationsPackageR `db:"-" ` +} + +// LocationsPackageSlice is an alias for a slice of pointers to LocationsPackage. +// This should almost always be used instead of []*LocationsPackage. +type LocationsPackageSlice []*LocationsPackage + +// LocationsPackages contains methods to work with the locations_package table +var LocationsPackages = mysql.NewTablex[*LocationsPackage, LocationsPackageSlice, *LocationsPackageSetter]("locations_package", buildLocationsPackageColumns("locations_package"), []string{"id"}, []string{"uuid"}) + +// LocationsPackagesQuery is a query on the locations_package table +type LocationsPackagesQuery = *mysql.ViewQuery[*LocationsPackage, LocationsPackageSlice] + +// locationsPackageR is where relationships are stored. +type locationsPackageR struct { + PackageLocationsEvents LocationsEventSlice // locations_event_package_id_50db610f_fk_locations_package_uuid + PackageLocationsFiles LocationsFileSlice // locations_file_package_id_dd478d69_fk_locations_package_id + PackageLocationsFixitylogs LocationsFixitylogSlice // locations_fixitylog_package_id_0201e98f_fk_locations + CurrentLocationLocationsLocation *LocationsLocation // locations_package_current_location_id_c8f7daee_fk_locations + OriginPipelineLocationsPipeline *LocationsPipeline // locations_package_origin_pipeline_id_9f8d6473_fk_locations + PointerFileLocationLocationsLocation *LocationsLocation // locations_package_pointer_file_locatio_2adf5d3c_fk_locations + FromPackageLocationsPackageRelatedPackages LocationsPackageRelatedPackageSlice // locations_package_re_from_package_id_eab8b60c_fk_locations + ToPackageLocationsPackageRelatedPackages LocationsPackageRelatedPackageSlice // locations_package_re_to_package_id_7a32b99c_fk_locations + ReplicatedPackage *LocationsPackage // locations_package_replicated_package_i_6db19821_fk_locations + ReverseReplicatedPackages LocationsPackageSlice // locations_package_replicated_package_i_6db19821_fk_locations__self_join_reverse + PackageLocationsPackagedownloadtasks LocationsPackagedownloadtaskSlice // locations_packagedow_package_id_488c7751_fk_locations +} + +func buildLocationsPackageColumns(alias string) locationsPackageColumns { + return locationsPackageColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "uuid", "current_path", "pointer_file_path", "size", "package_type", "status", "current_location_id", "origin_pipeline_id", "pointer_file_location_id", "misc_attributes", "description", "encryption_key_fingerprint", "replicated_package_id", "stored_date", "checksum", "checksum_algorithm", + ).WithParent("locations_package"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UUID: mysql.Quote(alias, "uuid"), + CurrentPath: mysql.Quote(alias, "current_path"), + PointerFilePath: mysql.Quote(alias, "pointer_file_path"), + Size: mysql.Quote(alias, "size"), + PackageType: mysql.Quote(alias, "package_type"), + Status: mysql.Quote(alias, "status"), + CurrentLocationID: mysql.Quote(alias, "current_location_id"), + OriginPipelineID: mysql.Quote(alias, "origin_pipeline_id"), + PointerFileLocationID: mysql.Quote(alias, "pointer_file_location_id"), + MiscAttributes: mysql.Quote(alias, "misc_attributes"), + Description: mysql.Quote(alias, "description"), + EncryptionKeyFingerprint: mysql.Quote(alias, "encryption_key_fingerprint"), + ReplicatedPackageID: mysql.Quote(alias, "replicated_package_id"), + StoredDate: mysql.Quote(alias, "stored_date"), + Checksum: mysql.Quote(alias, "checksum"), + ChecksumAlgorithm: mysql.Quote(alias, "checksum_algorithm"), + } +} + +type locationsPackageColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UUID mysql.Expression + CurrentPath mysql.Expression + PointerFilePath mysql.Expression + Size mysql.Expression + PackageType mysql.Expression + Status mysql.Expression + CurrentLocationID mysql.Expression + OriginPipelineID mysql.Expression + PointerFileLocationID mysql.Expression + MiscAttributes mysql.Expression + Description mysql.Expression + EncryptionKeyFingerprint mysql.Expression + ReplicatedPackageID mysql.Expression + StoredDate mysql.Expression + Checksum mysql.Expression + ChecksumAlgorithm mysql.Expression +} + +func (c locationsPackageColumns) Alias() string { + return c.tableAlias +} + +func (locationsPackageColumns) AliasedAs(alias string) locationsPackageColumns { + return buildLocationsPackageColumns(alias) +} + +// LocationsPackageSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsPackageSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UUID omit.Val[string] `db:"uuid" ` + CurrentPath omit.Val[string] `db:"current_path" ` + PointerFilePath omitnull.Val[string] `db:"pointer_file_path" ` + Size omit.Val[int64] `db:"size" ` + PackageType omit.Val[string] `db:"package_type" ` + Status omit.Val[string] `db:"status" ` + CurrentLocationID omit.Val[string] `db:"current_location_id" ` + OriginPipelineID omitnull.Val[string] `db:"origin_pipeline_id" ` + PointerFileLocationID omitnull.Val[string] `db:"pointer_file_location_id" ` + MiscAttributes omitnull.Val[string] `db:"misc_attributes" ` + Description omitnull.Val[string] `db:"description" ` + EncryptionKeyFingerprint omitnull.Val[string] `db:"encryption_key_fingerprint" ` + ReplicatedPackageID omitnull.Val[string] `db:"replicated_package_id" ` + StoredDate omitnull.Val[time.Time] `db:"stored_date" ` + Checksum omitnull.Val[string] `db:"checksum" ` + ChecksumAlgorithm omitnull.Val[string] `db:"checksum_algorithm" ` +} + +func (s LocationsPackageSetter) SetColumns() []string { + vals := make([]string, 0, 17) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UUID.IsValue() { + vals = append(vals, "uuid") + } + if s.CurrentPath.IsValue() { + vals = append(vals, "current_path") + } + if !s.PointerFilePath.IsUnset() { + vals = append(vals, "pointer_file_path") + } + if s.Size.IsValue() { + vals = append(vals, "size") + } + if s.PackageType.IsValue() { + vals = append(vals, "package_type") + } + if s.Status.IsValue() { + vals = append(vals, "status") + } + if s.CurrentLocationID.IsValue() { + vals = append(vals, "current_location_id") + } + if !s.OriginPipelineID.IsUnset() { + vals = append(vals, "origin_pipeline_id") + } + if !s.PointerFileLocationID.IsUnset() { + vals = append(vals, "pointer_file_location_id") + } + if !s.MiscAttributes.IsUnset() { + vals = append(vals, "misc_attributes") + } + if !s.Description.IsUnset() { + vals = append(vals, "description") + } + if !s.EncryptionKeyFingerprint.IsUnset() { + vals = append(vals, "encryption_key_fingerprint") + } + if !s.ReplicatedPackageID.IsUnset() { + vals = append(vals, "replicated_package_id") + } + if !s.StoredDate.IsUnset() { + vals = append(vals, "stored_date") + } + if !s.Checksum.IsUnset() { + vals = append(vals, "checksum") + } + if !s.ChecksumAlgorithm.IsUnset() { + vals = append(vals, "checksum_algorithm") + } + return vals +} + +func (s LocationsPackageSetter) Overwrite(t *LocationsPackage) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UUID.IsValue() { + t.UUID = s.UUID.MustGet() + } + if s.CurrentPath.IsValue() { + t.CurrentPath = s.CurrentPath.MustGet() + } + if !s.PointerFilePath.IsUnset() { + t.PointerFilePath = s.PointerFilePath.MustGetNull() + } + if s.Size.IsValue() { + t.Size = s.Size.MustGet() + } + if s.PackageType.IsValue() { + t.PackageType = s.PackageType.MustGet() + } + if s.Status.IsValue() { + t.Status = s.Status.MustGet() + } + if s.CurrentLocationID.IsValue() { + t.CurrentLocationID = s.CurrentLocationID.MustGet() + } + if !s.OriginPipelineID.IsUnset() { + t.OriginPipelineID = s.OriginPipelineID.MustGetNull() + } + if !s.PointerFileLocationID.IsUnset() { + t.PointerFileLocationID = s.PointerFileLocationID.MustGetNull() + } + if !s.MiscAttributes.IsUnset() { + t.MiscAttributes = s.MiscAttributes.MustGetNull() + } + if !s.Description.IsUnset() { + t.Description = s.Description.MustGetNull() + } + if !s.EncryptionKeyFingerprint.IsUnset() { + t.EncryptionKeyFingerprint = s.EncryptionKeyFingerprint.MustGetNull() + } + if !s.ReplicatedPackageID.IsUnset() { + t.ReplicatedPackageID = s.ReplicatedPackageID.MustGetNull() + } + if !s.StoredDate.IsUnset() { + t.StoredDate = s.StoredDate.MustGetNull() + } + if !s.Checksum.IsUnset() { + t.Checksum = s.Checksum.MustGetNull() + } + if !s.ChecksumAlgorithm.IsUnset() { + t.ChecksumAlgorithm = s.ChecksumAlgorithm.MustGetNull() + } +} + +func (s *LocationsPackageSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackages.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UUID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UUID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.CurrentPath.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.CurrentPath.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.PointerFilePath.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PointerFilePath.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Size.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Size.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.PackageType.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PackageType.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Status.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Status.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.CurrentLocationID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.CurrentLocationID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.OriginPipelineID.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.OriginPipelineID.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.PointerFileLocationID.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PointerFileLocationID.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.MiscAttributes.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.MiscAttributes.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Description.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Description.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.EncryptionKeyFingerprint.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.EncryptionKeyFingerprint.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.ReplicatedPackageID.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ReplicatedPackageID.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.StoredDate.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.StoredDate.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Checksum.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Checksum.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.ChecksumAlgorithm.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ChecksumAlgorithm.MustGetNull()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsPackageSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_package")...) +} + +func (s LocationsPackageSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 17) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UUID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uuid")...), + mysql.Arg(s.UUID), + }}) + } + + if s.CurrentPath.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "current_path")...), + mysql.Arg(s.CurrentPath), + }}) + } + + if !s.PointerFilePath.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "pointer_file_path")...), + mysql.Arg(s.PointerFilePath), + }}) + } + + if s.Size.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "size")...), + mysql.Arg(s.Size), + }}) + } + + if s.PackageType.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "package_type")...), + mysql.Arg(s.PackageType), + }}) + } + + if s.Status.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "status")...), + mysql.Arg(s.Status), + }}) + } + + if s.CurrentLocationID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "current_location_id")...), + mysql.Arg(s.CurrentLocationID), + }}) + } + + if !s.OriginPipelineID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "origin_pipeline_id")...), + mysql.Arg(s.OriginPipelineID), + }}) + } + + if !s.PointerFileLocationID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "pointer_file_location_id")...), + mysql.Arg(s.PointerFileLocationID), + }}) + } + + if !s.MiscAttributes.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "misc_attributes")...), + mysql.Arg(s.MiscAttributes), + }}) + } + + if !s.Description.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "description")...), + mysql.Arg(s.Description), + }}) + } + + if !s.EncryptionKeyFingerprint.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "encryption_key_fingerprint")...), + mysql.Arg(s.EncryptionKeyFingerprint), + }}) + } + + if !s.ReplicatedPackageID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "replicated_package_id")...), + mysql.Arg(s.ReplicatedPackageID), + }}) + } + + if !s.StoredDate.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "stored_date")...), + mysql.Arg(s.StoredDate), + }}) + } + + if !s.Checksum.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "checksum")...), + mysql.Arg(s.Checksum), + }}) + } + + if !s.ChecksumAlgorithm.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "checksum_algorithm")...), + mysql.Arg(s.ChecksumAlgorithm), + }}) + } + + return exprs +} + +// FindLocationsPackage retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsPackage(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsPackage, error) { + if len(cols) == 0 { + return LocationsPackages.Query( + sm.Where(LocationsPackages.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsPackages.Query( + sm.Where(LocationsPackages.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsPackages.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsPackageExists checks the presence of a single record by primary key +func LocationsPackageExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsPackages.Query( + sm.Where(LocationsPackages.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsPackage is retrieved from the database +func (o *LocationsPackage) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPackages.AfterSelectHooks.RunHooks(ctx, exec, LocationsPackageSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsPackages.AfterInsertHooks.RunHooks(ctx, exec, LocationsPackageSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsPackages.AfterUpdateHooks.RunHooks(ctx, exec, LocationsPackageSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsPackages.AfterDeleteHooks.RunHooks(ctx, exec, LocationsPackageSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsPackage +func (o *LocationsPackage) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsPackage) pkEQ() dialect.Expression { + return mysql.Quote("locations_package", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsPackage +func (o *LocationsPackage) Update(ctx context.Context, exec bob.Executor, s *LocationsPackageSetter) error { + _, err := LocationsPackages.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsPackage record with an executor +func (o *LocationsPackage) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsPackages.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsPackage using the executor +func (o *LocationsPackage) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsPackages.Query( + sm.Where(LocationsPackages.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsPackageSlice is retrieved from the database +func (o LocationsPackageSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPackages.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsPackages.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsPackages.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsPackages.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsPackageSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_package", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsPackageSlice) copyMatchingRows(from ...*LocationsPackage) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsPackageSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackages.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPackage: + o.copyMatchingRows(retrieved) + case []*LocationsPackage: + o.copyMatchingRows(retrieved...) + case LocationsPackageSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPackage or a slice of LocationsPackage + // then run the AfterUpdateHooks on the slice + _, err = LocationsPackages.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsPackageSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackages.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPackage: + o.copyMatchingRows(retrieved) + case []*LocationsPackage: + o.copyMatchingRows(retrieved...) + case LocationsPackageSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPackage or a slice of LocationsPackage + // then run the AfterDeleteHooks on the slice + _, err = LocationsPackages.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsPackageSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsPackageSetter) error { + _, err := LocationsPackages.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsPackageSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsPackages.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsPackageSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsPackages.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// PackageLocationsEvents starts a query for related objects on locations_event +func (o *LocationsPackage) PackageLocationsEvents(mods ...bob.Mod[*dialect.SelectQuery]) LocationsEventsQuery { + return LocationsEvents.Query(append(mods, + sm.Where(LocationsEvents.Columns.PackageID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsPackageSlice) PackageLocationsEvents(mods ...bob.Mod[*dialect.SelectQuery]) LocationsEventsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsEvents.Query(append(mods, + sm.Where(mysql.Group(LocationsEvents.Columns.PackageID).OP("IN", PKArgExpr)), + )...) +} + +// PackageLocationsFiles starts a query for related objects on locations_file +func (o *LocationsPackage) PackageLocationsFiles(mods ...bob.Mod[*dialect.SelectQuery]) LocationsFilesQuery { + return LocationsFiles.Query(append(mods, + sm.Where(LocationsFiles.Columns.PackageID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os LocationsPackageSlice) PackageLocationsFiles(mods ...bob.Mod[*dialect.SelectQuery]) LocationsFilesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsFiles.Query(append(mods, + sm.Where(mysql.Group(LocationsFiles.Columns.PackageID).OP("IN", PKArgExpr)), + )...) +} + +// PackageLocationsFixitylogs starts a query for related objects on locations_fixitylog +func (o *LocationsPackage) PackageLocationsFixitylogs(mods ...bob.Mod[*dialect.SelectQuery]) LocationsFixitylogsQuery { + return LocationsFixitylogs.Query(append(mods, + sm.Where(LocationsFixitylogs.Columns.PackageID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsPackageSlice) PackageLocationsFixitylogs(mods ...bob.Mod[*dialect.SelectQuery]) LocationsFixitylogsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsFixitylogs.Query(append(mods, + sm.Where(mysql.Group(LocationsFixitylogs.Columns.PackageID).OP("IN", PKArgExpr)), + )...) +} + +// CurrentLocationLocationsLocation starts a query for related objects on locations_location +func (o *LocationsPackage) CurrentLocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + return LocationsLocations.Query(append(mods, + sm.Where(LocationsLocations.Columns.UUID.EQ(mysql.Arg(o.CurrentLocationID))), + )...) +} + +func (os LocationsPackageSlice) CurrentLocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.CurrentLocationID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocations.Query(append(mods, + sm.Where(mysql.Group(LocationsLocations.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +// OriginPipelineLocationsPipeline starts a query for related objects on locations_pipeline +func (o *LocationsPackage) OriginPipelineLocationsPipeline(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPipelinesQuery { + return LocationsPipelines.Query(append(mods, + sm.Where(LocationsPipelines.Columns.UUID.EQ(mysql.Arg(o.OriginPipelineID))), + )...) +} + +func (os LocationsPackageSlice) OriginPipelineLocationsPipeline(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPipelinesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.OriginPipelineID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPipelines.Query(append(mods, + sm.Where(mysql.Group(LocationsPipelines.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +// PointerFileLocationLocationsLocation starts a query for related objects on locations_location +func (o *LocationsPackage) PointerFileLocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + return LocationsLocations.Query(append(mods, + sm.Where(LocationsLocations.Columns.UUID.EQ(mysql.Arg(o.PointerFileLocationID))), + )...) +} + +func (os LocationsPackageSlice) PointerFileLocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PointerFileLocationID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocations.Query(append(mods, + sm.Where(mysql.Group(LocationsLocations.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +// FromPackageLocationsPackageRelatedPackages starts a query for related objects on locations_package_related_packages +func (o *LocationsPackage) FromPackageLocationsPackageRelatedPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackageRelatedPackagesQuery { + return LocationsPackageRelatedPackages.Query(append(mods, + sm.Where(LocationsPackageRelatedPackages.Columns.FromPackageID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os LocationsPackageSlice) FromPackageLocationsPackageRelatedPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackageRelatedPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackageRelatedPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackageRelatedPackages.Columns.FromPackageID).OP("IN", PKArgExpr)), + )...) +} + +// ToPackageLocationsPackageRelatedPackages starts a query for related objects on locations_package_related_packages +func (o *LocationsPackage) ToPackageLocationsPackageRelatedPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackageRelatedPackagesQuery { + return LocationsPackageRelatedPackages.Query(append(mods, + sm.Where(LocationsPackageRelatedPackages.Columns.ToPackageID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os LocationsPackageSlice) ToPackageLocationsPackageRelatedPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackageRelatedPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackageRelatedPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackageRelatedPackages.Columns.ToPackageID).OP("IN", PKArgExpr)), + )...) +} + +// ReplicatedPackage starts a query for related objects on locations_package +func (o *LocationsPackage) ReplicatedPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.UUID.EQ(mysql.Arg(o.ReplicatedPackageID))), + )...) +} + +func (os LocationsPackageSlice) ReplicatedPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ReplicatedPackageID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +// ReverseReplicatedPackages starts a query for related objects on locations_package +func (o *LocationsPackage) ReverseReplicatedPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.ReplicatedPackageID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsPackageSlice) ReverseReplicatedPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.ReplicatedPackageID).OP("IN", PKArgExpr)), + )...) +} + +// PackageLocationsPackagedownloadtasks starts a query for related objects on locations_packagedownloadtask +func (o *LocationsPackage) PackageLocationsPackagedownloadtasks(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagedownloadtasksQuery { + return LocationsPackagedownloadtasks.Query(append(mods, + sm.Where(LocationsPackagedownloadtasks.Columns.PackageID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsPackageSlice) PackageLocationsPackagedownloadtasks(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagedownloadtasksQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackagedownloadtasks.Query(append(mods, + sm.Where(mysql.Group(LocationsPackagedownloadtasks.Columns.PackageID).OP("IN", PKArgExpr)), + )...) +} + +func insertLocationsPackagePackageLocationsEvents0(ctx context.Context, exec bob.Executor, locationsEvents1 []*LocationsEventSetter, locationsPackage0 *LocationsPackage) (LocationsEventSlice, error) { + for i := range locationsEvents1 { + locationsEvents1[i].PackageID = omit.From(locationsPackage0.UUID) + } + + ret, err := LocationsEvents.Insert(bob.ToMods(locationsEvents1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPackagePackageLocationsEvents0: %w", err) + } + + return ret, nil +} + +func attachLocationsPackagePackageLocationsEvents0(ctx context.Context, exec bob.Executor, count int, locationsEvents1 LocationsEventSlice, locationsPackage0 *LocationsPackage) (LocationsEventSlice, error) { + setter := &LocationsEventSetter{ + PackageID: omit.From(locationsPackage0.UUID), + } + + err := locationsEvents1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackagePackageLocationsEvents0: %w", err) + } + + return locationsEvents1, nil +} + +func (locationsPackage0 *LocationsPackage) InsertPackageLocationsEvents(ctx context.Context, exec bob.Executor, related ...*LocationsEventSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsEvents1, err := insertLocationsPackagePackageLocationsEvents0(ctx, exec, related, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.PackageLocationsEvents = append(locationsPackage0.R.PackageLocationsEvents, locationsEvents1...) + + for _, rel := range locationsEvents1 { + rel.R.PackageLocationsPackage = locationsPackage0 + } + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachPackageLocationsEvents(ctx context.Context, exec bob.Executor, related ...*LocationsEvent) error { + if len(related) == 0 { + return nil + } + + var err error + locationsEvents1 := LocationsEventSlice(related) + + _, err = attachLocationsPackagePackageLocationsEvents0(ctx, exec, len(related), locationsEvents1, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.PackageLocationsEvents = append(locationsPackage0.R.PackageLocationsEvents, locationsEvents1...) + + for _, rel := range related { + rel.R.PackageLocationsPackage = locationsPackage0 + } + + return nil +} + +func insertLocationsPackagePackageLocationsFiles0(ctx context.Context, exec bob.Executor, locationsFiles1 []*LocationsFileSetter, locationsPackage0 *LocationsPackage) (LocationsFileSlice, error) { + for i := range locationsFiles1 { + locationsFiles1[i].PackageID = omitnull.From(locationsPackage0.ID) + } + + ret, err := LocationsFiles.Insert(bob.ToMods(locationsFiles1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPackagePackageLocationsFiles0: %w", err) + } + + return ret, nil +} + +func attachLocationsPackagePackageLocationsFiles0(ctx context.Context, exec bob.Executor, count int, locationsFiles1 LocationsFileSlice, locationsPackage0 *LocationsPackage) (LocationsFileSlice, error) { + setter := &LocationsFileSetter{ + PackageID: omitnull.From(locationsPackage0.ID), + } + + err := locationsFiles1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackagePackageLocationsFiles0: %w", err) + } + + return locationsFiles1, nil +} + +func (locationsPackage0 *LocationsPackage) InsertPackageLocationsFiles(ctx context.Context, exec bob.Executor, related ...*LocationsFileSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsFiles1, err := insertLocationsPackagePackageLocationsFiles0(ctx, exec, related, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.PackageLocationsFiles = append(locationsPackage0.R.PackageLocationsFiles, locationsFiles1...) + + for _, rel := range locationsFiles1 { + rel.R.PackageLocationsPackage = locationsPackage0 + } + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachPackageLocationsFiles(ctx context.Context, exec bob.Executor, related ...*LocationsFile) error { + if len(related) == 0 { + return nil + } + + var err error + locationsFiles1 := LocationsFileSlice(related) + + _, err = attachLocationsPackagePackageLocationsFiles0(ctx, exec, len(related), locationsFiles1, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.PackageLocationsFiles = append(locationsPackage0.R.PackageLocationsFiles, locationsFiles1...) + + for _, rel := range related { + rel.R.PackageLocationsPackage = locationsPackage0 + } + + return nil +} + +func insertLocationsPackagePackageLocationsFixitylogs0(ctx context.Context, exec bob.Executor, locationsFixitylogs1 []*LocationsFixitylogSetter, locationsPackage0 *LocationsPackage) (LocationsFixitylogSlice, error) { + for i := range locationsFixitylogs1 { + locationsFixitylogs1[i].PackageID = omit.From(locationsPackage0.UUID) + } + + ret, err := LocationsFixitylogs.Insert(bob.ToMods(locationsFixitylogs1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPackagePackageLocationsFixitylogs0: %w", err) + } + + return ret, nil +} + +func attachLocationsPackagePackageLocationsFixitylogs0(ctx context.Context, exec bob.Executor, count int, locationsFixitylogs1 LocationsFixitylogSlice, locationsPackage0 *LocationsPackage) (LocationsFixitylogSlice, error) { + setter := &LocationsFixitylogSetter{ + PackageID: omit.From(locationsPackage0.UUID), + } + + err := locationsFixitylogs1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackagePackageLocationsFixitylogs0: %w", err) + } + + return locationsFixitylogs1, nil +} + +func (locationsPackage0 *LocationsPackage) InsertPackageLocationsFixitylogs(ctx context.Context, exec bob.Executor, related ...*LocationsFixitylogSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsFixitylogs1, err := insertLocationsPackagePackageLocationsFixitylogs0(ctx, exec, related, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.PackageLocationsFixitylogs = append(locationsPackage0.R.PackageLocationsFixitylogs, locationsFixitylogs1...) + + for _, rel := range locationsFixitylogs1 { + rel.R.PackageLocationsPackage = locationsPackage0 + } + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachPackageLocationsFixitylogs(ctx context.Context, exec bob.Executor, related ...*LocationsFixitylog) error { + if len(related) == 0 { + return nil + } + + var err error + locationsFixitylogs1 := LocationsFixitylogSlice(related) + + _, err = attachLocationsPackagePackageLocationsFixitylogs0(ctx, exec, len(related), locationsFixitylogs1, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.PackageLocationsFixitylogs = append(locationsPackage0.R.PackageLocationsFixitylogs, locationsFixitylogs1...) + + for _, rel := range related { + rel.R.PackageLocationsPackage = locationsPackage0 + } + + return nil +} + +func attachLocationsPackageCurrentLocationLocationsLocation0(ctx context.Context, exec bob.Executor, count int, locationsPackage0 *LocationsPackage, locationsLocation1 *LocationsLocation) (*LocationsPackage, error) { + setter := &LocationsPackageSetter{ + CurrentLocationID: omit.From(locationsLocation1.UUID), + } + + err := locationsPackage0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackageCurrentLocationLocationsLocation0: %w", err) + } + + return locationsPackage0, nil +} + +func (locationsPackage0 *LocationsPackage) InsertCurrentLocationLocationsLocation(ctx context.Context, exec bob.Executor, related *LocationsLocationSetter) error { + var err error + + locationsLocation1, err := LocationsLocations.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPackageCurrentLocationLocationsLocation0(ctx, exec, 1, locationsPackage0, locationsLocation1) + if err != nil { + return err + } + + locationsPackage0.R.CurrentLocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.CurrentLocationLocationsPackages = append(locationsLocation1.R.CurrentLocationLocationsPackages, locationsPackage0) + + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachCurrentLocationLocationsLocation(ctx context.Context, exec bob.Executor, locationsLocation1 *LocationsLocation) error { + var err error + + _, err = attachLocationsPackageCurrentLocationLocationsLocation0(ctx, exec, 1, locationsPackage0, locationsLocation1) + if err != nil { + return err + } + + locationsPackage0.R.CurrentLocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.CurrentLocationLocationsPackages = append(locationsLocation1.R.CurrentLocationLocationsPackages, locationsPackage0) + + return nil +} + +func attachLocationsPackageOriginPipelineLocationsPipeline0(ctx context.Context, exec bob.Executor, count int, locationsPackage0 *LocationsPackage, locationsPipeline1 *LocationsPipeline) (*LocationsPackage, error) { + setter := &LocationsPackageSetter{ + OriginPipelineID: omitnull.From(locationsPipeline1.UUID), + } + + err := locationsPackage0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackageOriginPipelineLocationsPipeline0: %w", err) + } + + return locationsPackage0, nil +} + +func (locationsPackage0 *LocationsPackage) InsertOriginPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, related *LocationsPipelineSetter) error { + var err error + + locationsPipeline1, err := LocationsPipelines.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPackageOriginPipelineLocationsPipeline0(ctx, exec, 1, locationsPackage0, locationsPipeline1) + if err != nil { + return err + } + + locationsPackage0.R.OriginPipelineLocationsPipeline = locationsPipeline1 + + locationsPipeline1.R.OriginPipelineLocationsPackages = append(locationsPipeline1.R.OriginPipelineLocationsPackages, locationsPackage0) + + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachOriginPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, locationsPipeline1 *LocationsPipeline) error { + var err error + + _, err = attachLocationsPackageOriginPipelineLocationsPipeline0(ctx, exec, 1, locationsPackage0, locationsPipeline1) + if err != nil { + return err + } + + locationsPackage0.R.OriginPipelineLocationsPipeline = locationsPipeline1 + + locationsPipeline1.R.OriginPipelineLocationsPackages = append(locationsPipeline1.R.OriginPipelineLocationsPackages, locationsPackage0) + + return nil +} + +func attachLocationsPackagePointerFileLocationLocationsLocation0(ctx context.Context, exec bob.Executor, count int, locationsPackage0 *LocationsPackage, locationsLocation1 *LocationsLocation) (*LocationsPackage, error) { + setter := &LocationsPackageSetter{ + PointerFileLocationID: omitnull.From(locationsLocation1.UUID), + } + + err := locationsPackage0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackagePointerFileLocationLocationsLocation0: %w", err) + } + + return locationsPackage0, nil +} + +func (locationsPackage0 *LocationsPackage) InsertPointerFileLocationLocationsLocation(ctx context.Context, exec bob.Executor, related *LocationsLocationSetter) error { + var err error + + locationsLocation1, err := LocationsLocations.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPackagePointerFileLocationLocationsLocation0(ctx, exec, 1, locationsPackage0, locationsLocation1) + if err != nil { + return err + } + + locationsPackage0.R.PointerFileLocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.PointerFileLocationLocationsPackages = append(locationsLocation1.R.PointerFileLocationLocationsPackages, locationsPackage0) + + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachPointerFileLocationLocationsLocation(ctx context.Context, exec bob.Executor, locationsLocation1 *LocationsLocation) error { + var err error + + _, err = attachLocationsPackagePointerFileLocationLocationsLocation0(ctx, exec, 1, locationsPackage0, locationsLocation1) + if err != nil { + return err + } + + locationsPackage0.R.PointerFileLocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.PointerFileLocationLocationsPackages = append(locationsLocation1.R.PointerFileLocationLocationsPackages, locationsPackage0) + + return nil +} + +func insertLocationsPackageFromPackageLocationsPackageRelatedPackages0(ctx context.Context, exec bob.Executor, locationsPackageRelatedPackages1 []*LocationsPackageRelatedPackageSetter, locationsPackage0 *LocationsPackage) (LocationsPackageRelatedPackageSlice, error) { + for i := range locationsPackageRelatedPackages1 { + locationsPackageRelatedPackages1[i].FromPackageID = omit.From(locationsPackage0.ID) + } + + ret, err := LocationsPackageRelatedPackages.Insert(bob.ToMods(locationsPackageRelatedPackages1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPackageFromPackageLocationsPackageRelatedPackages0: %w", err) + } + + return ret, nil +} + +func attachLocationsPackageFromPackageLocationsPackageRelatedPackages0(ctx context.Context, exec bob.Executor, count int, locationsPackageRelatedPackages1 LocationsPackageRelatedPackageSlice, locationsPackage0 *LocationsPackage) (LocationsPackageRelatedPackageSlice, error) { + setter := &LocationsPackageRelatedPackageSetter{ + FromPackageID: omit.From(locationsPackage0.ID), + } + + err := locationsPackageRelatedPackages1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackageFromPackageLocationsPackageRelatedPackages0: %w", err) + } + + return locationsPackageRelatedPackages1, nil +} + +func (locationsPackage0 *LocationsPackage) InsertFromPackageLocationsPackageRelatedPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackageRelatedPackageSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsPackageRelatedPackages1, err := insertLocationsPackageFromPackageLocationsPackageRelatedPackages0(ctx, exec, related, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.FromPackageLocationsPackageRelatedPackages = append(locationsPackage0.R.FromPackageLocationsPackageRelatedPackages, locationsPackageRelatedPackages1...) + + for _, rel := range locationsPackageRelatedPackages1 { + rel.R.FromPackageLocationsPackage = locationsPackage0 + } + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachFromPackageLocationsPackageRelatedPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackageRelatedPackage) error { + if len(related) == 0 { + return nil + } + + var err error + locationsPackageRelatedPackages1 := LocationsPackageRelatedPackageSlice(related) + + _, err = attachLocationsPackageFromPackageLocationsPackageRelatedPackages0(ctx, exec, len(related), locationsPackageRelatedPackages1, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.FromPackageLocationsPackageRelatedPackages = append(locationsPackage0.R.FromPackageLocationsPackageRelatedPackages, locationsPackageRelatedPackages1...) + + for _, rel := range related { + rel.R.FromPackageLocationsPackage = locationsPackage0 + } + + return nil +} + +func insertLocationsPackageToPackageLocationsPackageRelatedPackages0(ctx context.Context, exec bob.Executor, locationsPackageRelatedPackages1 []*LocationsPackageRelatedPackageSetter, locationsPackage0 *LocationsPackage) (LocationsPackageRelatedPackageSlice, error) { + for i := range locationsPackageRelatedPackages1 { + locationsPackageRelatedPackages1[i].ToPackageID = omit.From(locationsPackage0.ID) + } + + ret, err := LocationsPackageRelatedPackages.Insert(bob.ToMods(locationsPackageRelatedPackages1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPackageToPackageLocationsPackageRelatedPackages0: %w", err) + } + + return ret, nil +} + +func attachLocationsPackageToPackageLocationsPackageRelatedPackages0(ctx context.Context, exec bob.Executor, count int, locationsPackageRelatedPackages1 LocationsPackageRelatedPackageSlice, locationsPackage0 *LocationsPackage) (LocationsPackageRelatedPackageSlice, error) { + setter := &LocationsPackageRelatedPackageSetter{ + ToPackageID: omit.From(locationsPackage0.ID), + } + + err := locationsPackageRelatedPackages1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackageToPackageLocationsPackageRelatedPackages0: %w", err) + } + + return locationsPackageRelatedPackages1, nil +} + +func (locationsPackage0 *LocationsPackage) InsertToPackageLocationsPackageRelatedPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackageRelatedPackageSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsPackageRelatedPackages1, err := insertLocationsPackageToPackageLocationsPackageRelatedPackages0(ctx, exec, related, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.ToPackageLocationsPackageRelatedPackages = append(locationsPackage0.R.ToPackageLocationsPackageRelatedPackages, locationsPackageRelatedPackages1...) + + for _, rel := range locationsPackageRelatedPackages1 { + rel.R.ToPackageLocationsPackage = locationsPackage0 + } + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachToPackageLocationsPackageRelatedPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackageRelatedPackage) error { + if len(related) == 0 { + return nil + } + + var err error + locationsPackageRelatedPackages1 := LocationsPackageRelatedPackageSlice(related) + + _, err = attachLocationsPackageToPackageLocationsPackageRelatedPackages0(ctx, exec, len(related), locationsPackageRelatedPackages1, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.ToPackageLocationsPackageRelatedPackages = append(locationsPackage0.R.ToPackageLocationsPackageRelatedPackages, locationsPackageRelatedPackages1...) + + for _, rel := range related { + rel.R.ToPackageLocationsPackage = locationsPackage0 + } + + return nil +} + +func attachLocationsPackageReplicatedPackage0(ctx context.Context, exec bob.Executor, count int, locationsPackage0 *LocationsPackage, locationsPackage1 *LocationsPackage) (*LocationsPackage, error) { + setter := &LocationsPackageSetter{ + ReplicatedPackageID: omitnull.From(locationsPackage1.UUID), + } + + err := locationsPackage0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackageReplicatedPackage0: %w", err) + } + + return locationsPackage0, nil +} + +func (locationsPackage0 *LocationsPackage) InsertReplicatedPackage(ctx context.Context, exec bob.Executor, related *LocationsPackageSetter) error { + var err error + + locationsPackage1, err := LocationsPackages.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPackageReplicatedPackage0(ctx, exec, 1, locationsPackage0, locationsPackage1) + if err != nil { + return err + } + + locationsPackage0.R.ReplicatedPackage = locationsPackage1 + + locationsPackage1.R.ReplicatedPackage = locationsPackage0 + + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachReplicatedPackage(ctx context.Context, exec bob.Executor, locationsPackage1 *LocationsPackage) error { + var err error + + _, err = attachLocationsPackageReplicatedPackage0(ctx, exec, 1, locationsPackage0, locationsPackage1) + if err != nil { + return err + } + + locationsPackage0.R.ReplicatedPackage = locationsPackage1 + + locationsPackage1.R.ReplicatedPackage = locationsPackage0 + + return nil +} + +func insertLocationsPackageReverseReplicatedPackages0(ctx context.Context, exec bob.Executor, locationsPackages1 []*LocationsPackageSetter, locationsPackage0 *LocationsPackage) (LocationsPackageSlice, error) { + for i := range locationsPackages1 { + locationsPackages1[i].ReplicatedPackageID = omitnull.From(locationsPackage0.UUID) + } + + ret, err := LocationsPackages.Insert(bob.ToMods(locationsPackages1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPackageReverseReplicatedPackages0: %w", err) + } + + return ret, nil +} + +func attachLocationsPackageReverseReplicatedPackages0(ctx context.Context, exec bob.Executor, count int, locationsPackages1 LocationsPackageSlice, locationsPackage0 *LocationsPackage) (LocationsPackageSlice, error) { + setter := &LocationsPackageSetter{ + ReplicatedPackageID: omitnull.From(locationsPackage0.UUID), + } + + err := locationsPackages1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackageReverseReplicatedPackages0: %w", err) + } + + return locationsPackages1, nil +} + +func (locationsPackage0 *LocationsPackage) InsertReverseReplicatedPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackageSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsPackages1, err := insertLocationsPackageReverseReplicatedPackages0(ctx, exec, related, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.ReverseReplicatedPackages = append(locationsPackage0.R.ReverseReplicatedPackages, locationsPackages1...) + + for _, rel := range locationsPackages1 { + rel.R.ReverseReplicatedPackages = append(rel.R.ReverseReplicatedPackages, locationsPackage0) + } + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachReverseReplicatedPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackage) error { + if len(related) == 0 { + return nil + } + + var err error + locationsPackages1 := LocationsPackageSlice(related) + + _, err = attachLocationsPackageReverseReplicatedPackages0(ctx, exec, len(related), locationsPackages1, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.ReverseReplicatedPackages = append(locationsPackage0.R.ReverseReplicatedPackages, locationsPackages1...) + + for _, rel := range related { + rel.R.ReverseReplicatedPackages = append(rel.R.ReverseReplicatedPackages, locationsPackage0) + } + + return nil +} + +func insertLocationsPackagePackageLocationsPackagedownloadtasks0(ctx context.Context, exec bob.Executor, locationsPackagedownloadtasks1 []*LocationsPackagedownloadtaskSetter, locationsPackage0 *LocationsPackage) (LocationsPackagedownloadtaskSlice, error) { + for i := range locationsPackagedownloadtasks1 { + locationsPackagedownloadtasks1[i].PackageID = omit.From(locationsPackage0.UUID) + } + + ret, err := LocationsPackagedownloadtasks.Insert(bob.ToMods(locationsPackagedownloadtasks1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPackagePackageLocationsPackagedownloadtasks0: %w", err) + } + + return ret, nil +} + +func attachLocationsPackagePackageLocationsPackagedownloadtasks0(ctx context.Context, exec bob.Executor, count int, locationsPackagedownloadtasks1 LocationsPackagedownloadtaskSlice, locationsPackage0 *LocationsPackage) (LocationsPackagedownloadtaskSlice, error) { + setter := &LocationsPackagedownloadtaskSetter{ + PackageID: omit.From(locationsPackage0.UUID), + } + + err := locationsPackagedownloadtasks1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackagePackageLocationsPackagedownloadtasks0: %w", err) + } + + return locationsPackagedownloadtasks1, nil +} + +func (locationsPackage0 *LocationsPackage) InsertPackageLocationsPackagedownloadtasks(ctx context.Context, exec bob.Executor, related ...*LocationsPackagedownloadtaskSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsPackagedownloadtasks1, err := insertLocationsPackagePackageLocationsPackagedownloadtasks0(ctx, exec, related, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.PackageLocationsPackagedownloadtasks = append(locationsPackage0.R.PackageLocationsPackagedownloadtasks, locationsPackagedownloadtasks1...) + + for _, rel := range locationsPackagedownloadtasks1 { + rel.R.PackageLocationsPackage = locationsPackage0 + } + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachPackageLocationsPackagedownloadtasks(ctx context.Context, exec bob.Executor, related ...*LocationsPackagedownloadtask) error { + if len(related) == 0 { + return nil + } + + var err error + locationsPackagedownloadtasks1 := LocationsPackagedownloadtaskSlice(related) + + _, err = attachLocationsPackagePackageLocationsPackagedownloadtasks0(ctx, exec, len(related), locationsPackagedownloadtasks1, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.PackageLocationsPackagedownloadtasks = append(locationsPackage0.R.PackageLocationsPackagedownloadtasks, locationsPackagedownloadtasks1...) + + for _, rel := range related { + rel.R.PackageLocationsPackage = locationsPackage0 + } + + return nil +} + +type locationsPackageWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UUID mysql.WhereMod[Q, string] + CurrentPath mysql.WhereMod[Q, string] + PointerFilePath mysql.WhereNullMod[Q, string] + Size mysql.WhereMod[Q, int64] + PackageType mysql.WhereMod[Q, string] + Status mysql.WhereMod[Q, string] + CurrentLocationID mysql.WhereMod[Q, string] + OriginPipelineID mysql.WhereNullMod[Q, string] + PointerFileLocationID mysql.WhereNullMod[Q, string] + MiscAttributes mysql.WhereNullMod[Q, string] + Description mysql.WhereNullMod[Q, string] + EncryptionKeyFingerprint mysql.WhereNullMod[Q, string] + ReplicatedPackageID mysql.WhereNullMod[Q, string] + StoredDate mysql.WhereNullMod[Q, time.Time] + Checksum mysql.WhereNullMod[Q, string] + ChecksumAlgorithm mysql.WhereNullMod[Q, string] +} + +func (locationsPackageWhere[Q]) AliasedAs(alias string) locationsPackageWhere[Q] { + return buildLocationsPackageWhere[Q](buildLocationsPackageColumns(alias)) +} + +func buildLocationsPackageWhere[Q mysql.Filterable](cols locationsPackageColumns) locationsPackageWhere[Q] { + return locationsPackageWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UUID: mysql.Where[Q, string](cols.UUID), + CurrentPath: mysql.Where[Q, string](cols.CurrentPath), + PointerFilePath: mysql.WhereNull[Q, string](cols.PointerFilePath), + Size: mysql.Where[Q, int64](cols.Size), + PackageType: mysql.Where[Q, string](cols.PackageType), + Status: mysql.Where[Q, string](cols.Status), + CurrentLocationID: mysql.Where[Q, string](cols.CurrentLocationID), + OriginPipelineID: mysql.WhereNull[Q, string](cols.OriginPipelineID), + PointerFileLocationID: mysql.WhereNull[Q, string](cols.PointerFileLocationID), + MiscAttributes: mysql.WhereNull[Q, string](cols.MiscAttributes), + Description: mysql.WhereNull[Q, string](cols.Description), + EncryptionKeyFingerprint: mysql.WhereNull[Q, string](cols.EncryptionKeyFingerprint), + ReplicatedPackageID: mysql.WhereNull[Q, string](cols.ReplicatedPackageID), + StoredDate: mysql.WhereNull[Q, time.Time](cols.StoredDate), + Checksum: mysql.WhereNull[Q, string](cols.Checksum), + ChecksumAlgorithm: mysql.WhereNull[Q, string](cols.ChecksumAlgorithm), + } +} + +func (o *LocationsPackage) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "PackageLocationsEvents": + rels, ok := retrieved.(LocationsEventSlice) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.PackageLocationsEvents = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PackageLocationsPackage = o + } + } + return nil + case "PackageLocationsFiles": + rels, ok := retrieved.(LocationsFileSlice) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.PackageLocationsFiles = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PackageLocationsPackage = o + } + } + return nil + case "PackageLocationsFixitylogs": + rels, ok := retrieved.(LocationsFixitylogSlice) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.PackageLocationsFixitylogs = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PackageLocationsPackage = o + } + } + return nil + case "CurrentLocationLocationsLocation": + rel, ok := retrieved.(*LocationsLocation) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.CurrentLocationLocationsLocation = rel + + if rel != nil { + rel.R.CurrentLocationLocationsPackages = LocationsPackageSlice{o} + } + return nil + case "OriginPipelineLocationsPipeline": + rel, ok := retrieved.(*LocationsPipeline) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.OriginPipelineLocationsPipeline = rel + + if rel != nil { + rel.R.OriginPipelineLocationsPackages = LocationsPackageSlice{o} + } + return nil + case "PointerFileLocationLocationsLocation": + rel, ok := retrieved.(*LocationsLocation) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.PointerFileLocationLocationsLocation = rel + + if rel != nil { + rel.R.PointerFileLocationLocationsPackages = LocationsPackageSlice{o} + } + return nil + case "FromPackageLocationsPackageRelatedPackages": + rels, ok := retrieved.(LocationsPackageRelatedPackageSlice) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.FromPackageLocationsPackageRelatedPackages = rels + + for _, rel := range rels { + if rel != nil { + rel.R.FromPackageLocationsPackage = o + } + } + return nil + case "ToPackageLocationsPackageRelatedPackages": + rels, ok := retrieved.(LocationsPackageRelatedPackageSlice) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.ToPackageLocationsPackageRelatedPackages = rels + + for _, rel := range rels { + if rel != nil { + rel.R.ToPackageLocationsPackage = o + } + } + return nil + case "ReplicatedPackage": + rel, ok := retrieved.(*LocationsPackage) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.ReplicatedPackage = rel + + if rel != nil { + rel.R.ReplicatedPackage = o + } + return nil + case "ReverseReplicatedPackages": + rels, ok := retrieved.(LocationsPackageSlice) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.ReverseReplicatedPackages = rels + + for _, rel := range rels { + if rel != nil { + rel.R.ReverseReplicatedPackages = LocationsPackageSlice{o} + } + } + return nil + case "PackageLocationsPackagedownloadtasks": + rels, ok := retrieved.(LocationsPackagedownloadtaskSlice) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.PackageLocationsPackagedownloadtasks = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PackageLocationsPackage = o + } + } + return nil + default: + return fmt.Errorf("locationsPackage has no relationship %q", name) + } +} + +type locationsPackagePreloader struct { + CurrentLocationLocationsLocation func(...mysql.PreloadOption) mysql.Preloader + OriginPipelineLocationsPipeline func(...mysql.PreloadOption) mysql.Preloader + PointerFileLocationLocationsLocation func(...mysql.PreloadOption) mysql.Preloader + ReplicatedPackage func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsPackagePreloader() locationsPackagePreloader { + return locationsPackagePreloader{ + CurrentLocationLocationsLocation: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsLocation, LocationsLocationSlice](mysql.PreloadRel{ + Name: "CurrentLocationLocationsLocation", + Sides: []mysql.PreloadSide{ + { + From: LocationsPackages, + To: LocationsLocations, + FromColumns: []string{"current_location_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsLocations.Columns.Names(), opts...) + }, + OriginPipelineLocationsPipeline: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPipeline, LocationsPipelineSlice](mysql.PreloadRel{ + Name: "OriginPipelineLocationsPipeline", + Sides: []mysql.PreloadSide{ + { + From: LocationsPackages, + To: LocationsPipelines, + FromColumns: []string{"origin_pipeline_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsPipelines.Columns.Names(), opts...) + }, + PointerFileLocationLocationsLocation: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsLocation, LocationsLocationSlice](mysql.PreloadRel{ + Name: "PointerFileLocationLocationsLocation", + Sides: []mysql.PreloadSide{ + { + From: LocationsPackages, + To: LocationsLocations, + FromColumns: []string{"pointer_file_location_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsLocations.Columns.Names(), opts...) + }, + ReplicatedPackage: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPackage, LocationsPackageSlice](mysql.PreloadRel{ + Name: "ReplicatedPackage", + Sides: []mysql.PreloadSide{ + { + From: LocationsPackages, + To: LocationsPackages, + FromColumns: []string{"replicated_package_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsPackages.Columns.Names(), opts...) + }, + } +} + +type locationsPackageThenLoader[Q orm.Loadable] struct { + PackageLocationsEvents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PackageLocationsFiles func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PackageLocationsFixitylogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + CurrentLocationLocationsLocation func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + OriginPipelineLocationsPipeline func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PointerFileLocationLocationsLocation func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + FromPackageLocationsPackageRelatedPackages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ToPackageLocationsPackageRelatedPackages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ReplicatedPackage func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ReverseReplicatedPackages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PackageLocationsPackagedownloadtasks func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsPackageThenLoader[Q orm.Loadable]() locationsPackageThenLoader[Q] { + type PackageLocationsEventsLoadInterface interface { + LoadPackageLocationsEvents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PackageLocationsFilesLoadInterface interface { + LoadPackageLocationsFiles(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PackageLocationsFixitylogsLoadInterface interface { + LoadPackageLocationsFixitylogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type CurrentLocationLocationsLocationLoadInterface interface { + LoadCurrentLocationLocationsLocation(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type OriginPipelineLocationsPipelineLoadInterface interface { + LoadOriginPipelineLocationsPipeline(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PointerFileLocationLocationsLocationLoadInterface interface { + LoadPointerFileLocationLocationsLocation(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type FromPackageLocationsPackageRelatedPackagesLoadInterface interface { + LoadFromPackageLocationsPackageRelatedPackages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ToPackageLocationsPackageRelatedPackagesLoadInterface interface { + LoadToPackageLocationsPackageRelatedPackages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ReplicatedPackageLoadInterface interface { + LoadReplicatedPackage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ReverseReplicatedPackagesLoadInterface interface { + LoadReverseReplicatedPackages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PackageLocationsPackagedownloadtasksLoadInterface interface { + LoadPackageLocationsPackagedownloadtasks(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsPackageThenLoader[Q]{ + PackageLocationsEvents: thenLoadBuilder[Q]( + "PackageLocationsEvents", + func(ctx context.Context, exec bob.Executor, retrieved PackageLocationsEventsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPackageLocationsEvents(ctx, exec, mods...) + }, + ), + PackageLocationsFiles: thenLoadBuilder[Q]( + "PackageLocationsFiles", + func(ctx context.Context, exec bob.Executor, retrieved PackageLocationsFilesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPackageLocationsFiles(ctx, exec, mods...) + }, + ), + PackageLocationsFixitylogs: thenLoadBuilder[Q]( + "PackageLocationsFixitylogs", + func(ctx context.Context, exec bob.Executor, retrieved PackageLocationsFixitylogsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPackageLocationsFixitylogs(ctx, exec, mods...) + }, + ), + CurrentLocationLocationsLocation: thenLoadBuilder[Q]( + "CurrentLocationLocationsLocation", + func(ctx context.Context, exec bob.Executor, retrieved CurrentLocationLocationsLocationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadCurrentLocationLocationsLocation(ctx, exec, mods...) + }, + ), + OriginPipelineLocationsPipeline: thenLoadBuilder[Q]( + "OriginPipelineLocationsPipeline", + func(ctx context.Context, exec bob.Executor, retrieved OriginPipelineLocationsPipelineLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadOriginPipelineLocationsPipeline(ctx, exec, mods...) + }, + ), + PointerFileLocationLocationsLocation: thenLoadBuilder[Q]( + "PointerFileLocationLocationsLocation", + func(ctx context.Context, exec bob.Executor, retrieved PointerFileLocationLocationsLocationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPointerFileLocationLocationsLocation(ctx, exec, mods...) + }, + ), + FromPackageLocationsPackageRelatedPackages: thenLoadBuilder[Q]( + "FromPackageLocationsPackageRelatedPackages", + func(ctx context.Context, exec bob.Executor, retrieved FromPackageLocationsPackageRelatedPackagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadFromPackageLocationsPackageRelatedPackages(ctx, exec, mods...) + }, + ), + ToPackageLocationsPackageRelatedPackages: thenLoadBuilder[Q]( + "ToPackageLocationsPackageRelatedPackages", + func(ctx context.Context, exec bob.Executor, retrieved ToPackageLocationsPackageRelatedPackagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadToPackageLocationsPackageRelatedPackages(ctx, exec, mods...) + }, + ), + ReplicatedPackage: thenLoadBuilder[Q]( + "ReplicatedPackage", + func(ctx context.Context, exec bob.Executor, retrieved ReplicatedPackageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadReplicatedPackage(ctx, exec, mods...) + }, + ), + ReverseReplicatedPackages: thenLoadBuilder[Q]( + "ReverseReplicatedPackages", + func(ctx context.Context, exec bob.Executor, retrieved ReverseReplicatedPackagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadReverseReplicatedPackages(ctx, exec, mods...) + }, + ), + PackageLocationsPackagedownloadtasks: thenLoadBuilder[Q]( + "PackageLocationsPackagedownloadtasks", + func(ctx context.Context, exec bob.Executor, retrieved PackageLocationsPackagedownloadtasksLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPackageLocationsPackagedownloadtasks(ctx, exec, mods...) + }, + ), + } +} + +// LoadPackageLocationsEvents loads the locationsPackage's PackageLocationsEvents into the .R struct +func (o *LocationsPackage) LoadPackageLocationsEvents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PackageLocationsEvents = nil + + related, err := o.PackageLocationsEvents(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PackageLocationsPackage = o + } + + o.R.PackageLocationsEvents = related + return nil +} + +// LoadPackageLocationsEvents loads the locationsPackage's PackageLocationsEvents into the .R struct +func (os LocationsPackageSlice) LoadPackageLocationsEvents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsEvents, err := os.PackageLocationsEvents(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PackageLocationsEvents = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsEvents { + + if !(o.UUID == rel.PackageID) { + continue + } + + rel.R.PackageLocationsPackage = o + + o.R.PackageLocationsEvents = append(o.R.PackageLocationsEvents, rel) + } + } + + return nil +} + +// LoadPackageLocationsFiles loads the locationsPackage's PackageLocationsFiles into the .R struct +func (o *LocationsPackage) LoadPackageLocationsFiles(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PackageLocationsFiles = nil + + related, err := o.PackageLocationsFiles(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PackageLocationsPackage = o + } + + o.R.PackageLocationsFiles = related + return nil +} + +// LoadPackageLocationsFiles loads the locationsPackage's PackageLocationsFiles into the .R struct +func (os LocationsPackageSlice) LoadPackageLocationsFiles(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsFiles, err := os.PackageLocationsFiles(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PackageLocationsFiles = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsFiles { + + if !rel.PackageID.IsValue() { + continue + } + if !(rel.PackageID.IsValue() && o.ID == rel.PackageID.MustGet()) { + continue + } + + rel.R.PackageLocationsPackage = o + + o.R.PackageLocationsFiles = append(o.R.PackageLocationsFiles, rel) + } + } + + return nil +} + +// LoadPackageLocationsFixitylogs loads the locationsPackage's PackageLocationsFixitylogs into the .R struct +func (o *LocationsPackage) LoadPackageLocationsFixitylogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PackageLocationsFixitylogs = nil + + related, err := o.PackageLocationsFixitylogs(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PackageLocationsPackage = o + } + + o.R.PackageLocationsFixitylogs = related + return nil +} + +// LoadPackageLocationsFixitylogs loads the locationsPackage's PackageLocationsFixitylogs into the .R struct +func (os LocationsPackageSlice) LoadPackageLocationsFixitylogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsFixitylogs, err := os.PackageLocationsFixitylogs(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PackageLocationsFixitylogs = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsFixitylogs { + + if !(o.UUID == rel.PackageID) { + continue + } + + rel.R.PackageLocationsPackage = o + + o.R.PackageLocationsFixitylogs = append(o.R.PackageLocationsFixitylogs, rel) + } + } + + return nil +} + +// LoadCurrentLocationLocationsLocation loads the locationsPackage's CurrentLocationLocationsLocation into the .R struct +func (o *LocationsPackage) LoadCurrentLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.CurrentLocationLocationsLocation = nil + + related, err := o.CurrentLocationLocationsLocation(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.CurrentLocationLocationsPackages = LocationsPackageSlice{o} + + o.R.CurrentLocationLocationsLocation = related + return nil +} + +// LoadCurrentLocationLocationsLocation loads the locationsPackage's CurrentLocationLocationsLocation into the .R struct +func (os LocationsPackageSlice) LoadCurrentLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocations, err := os.CurrentLocationLocationsLocation(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocations { + + if !(o.CurrentLocationID == rel.UUID) { + continue + } + + rel.R.CurrentLocationLocationsPackages = append(rel.R.CurrentLocationLocationsPackages, o) + + o.R.CurrentLocationLocationsLocation = rel + break + } + } + + return nil +} + +// LoadOriginPipelineLocationsPipeline loads the locationsPackage's OriginPipelineLocationsPipeline into the .R struct +func (o *LocationsPackage) LoadOriginPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.OriginPipelineLocationsPipeline = nil + + related, err := o.OriginPipelineLocationsPipeline(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.OriginPipelineLocationsPackages = LocationsPackageSlice{o} + + o.R.OriginPipelineLocationsPipeline = related + return nil +} + +// LoadOriginPipelineLocationsPipeline loads the locationsPackage's OriginPipelineLocationsPipeline into the .R struct +func (os LocationsPackageSlice) LoadOriginPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPipelines, err := os.OriginPipelineLocationsPipeline(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPipelines { + if !o.OriginPipelineID.IsValue() { + continue + } + + if !(o.OriginPipelineID.IsValue() && o.OriginPipelineID.MustGet() == rel.UUID) { + continue + } + + rel.R.OriginPipelineLocationsPackages = append(rel.R.OriginPipelineLocationsPackages, o) + + o.R.OriginPipelineLocationsPipeline = rel + break + } + } + + return nil +} + +// LoadPointerFileLocationLocationsLocation loads the locationsPackage's PointerFileLocationLocationsLocation into the .R struct +func (o *LocationsPackage) LoadPointerFileLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PointerFileLocationLocationsLocation = nil + + related, err := o.PointerFileLocationLocationsLocation(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PointerFileLocationLocationsPackages = LocationsPackageSlice{o} + + o.R.PointerFileLocationLocationsLocation = related + return nil +} + +// LoadPointerFileLocationLocationsLocation loads the locationsPackage's PointerFileLocationLocationsLocation into the .R struct +func (os LocationsPackageSlice) LoadPointerFileLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocations, err := os.PointerFileLocationLocationsLocation(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocations { + if !o.PointerFileLocationID.IsValue() { + continue + } + + if !(o.PointerFileLocationID.IsValue() && o.PointerFileLocationID.MustGet() == rel.UUID) { + continue + } + + rel.R.PointerFileLocationLocationsPackages = append(rel.R.PointerFileLocationLocationsPackages, o) + + o.R.PointerFileLocationLocationsLocation = rel + break + } + } + + return nil +} + +// LoadFromPackageLocationsPackageRelatedPackages loads the locationsPackage's FromPackageLocationsPackageRelatedPackages into the .R struct +func (o *LocationsPackage) LoadFromPackageLocationsPackageRelatedPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.FromPackageLocationsPackageRelatedPackages = nil + + related, err := o.FromPackageLocationsPackageRelatedPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.FromPackageLocationsPackage = o + } + + o.R.FromPackageLocationsPackageRelatedPackages = related + return nil +} + +// LoadFromPackageLocationsPackageRelatedPackages loads the locationsPackage's FromPackageLocationsPackageRelatedPackages into the .R struct +func (os LocationsPackageSlice) LoadFromPackageLocationsPackageRelatedPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackageRelatedPackages, err := os.FromPackageLocationsPackageRelatedPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.FromPackageLocationsPackageRelatedPackages = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackageRelatedPackages { + + if !(o.ID == rel.FromPackageID) { + continue + } + + rel.R.FromPackageLocationsPackage = o + + o.R.FromPackageLocationsPackageRelatedPackages = append(o.R.FromPackageLocationsPackageRelatedPackages, rel) + } + } + + return nil +} + +// LoadToPackageLocationsPackageRelatedPackages loads the locationsPackage's ToPackageLocationsPackageRelatedPackages into the .R struct +func (o *LocationsPackage) LoadToPackageLocationsPackageRelatedPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ToPackageLocationsPackageRelatedPackages = nil + + related, err := o.ToPackageLocationsPackageRelatedPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.ToPackageLocationsPackage = o + } + + o.R.ToPackageLocationsPackageRelatedPackages = related + return nil +} + +// LoadToPackageLocationsPackageRelatedPackages loads the locationsPackage's ToPackageLocationsPackageRelatedPackages into the .R struct +func (os LocationsPackageSlice) LoadToPackageLocationsPackageRelatedPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackageRelatedPackages, err := os.ToPackageLocationsPackageRelatedPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.ToPackageLocationsPackageRelatedPackages = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackageRelatedPackages { + + if !(o.ID == rel.ToPackageID) { + continue + } + + rel.R.ToPackageLocationsPackage = o + + o.R.ToPackageLocationsPackageRelatedPackages = append(o.R.ToPackageLocationsPackageRelatedPackages, rel) + } + } + + return nil +} + +// LoadReplicatedPackage loads the locationsPackage's ReplicatedPackage into the .R struct +func (o *LocationsPackage) LoadReplicatedPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ReplicatedPackage = nil + + related, err := o.ReplicatedPackage(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.ReplicatedPackage = o + + o.R.ReplicatedPackage = related + return nil +} + +// LoadReplicatedPackage loads the locationsPackage's ReplicatedPackage into the .R struct +func (os LocationsPackageSlice) LoadReplicatedPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.ReplicatedPackage(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + if !o.ReplicatedPackageID.IsValue() { + continue + } + + if !(o.ReplicatedPackageID.IsValue() && o.ReplicatedPackageID.MustGet() == rel.UUID) { + continue + } + + rel.R.ReplicatedPackage = o + + o.R.ReplicatedPackage = rel + break + } + } + + return nil +} + +// LoadReverseReplicatedPackages loads the locationsPackage's ReverseReplicatedPackages into the .R struct +func (o *LocationsPackage) LoadReverseReplicatedPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ReverseReplicatedPackages = nil + + related, err := o.ReverseReplicatedPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.ReverseReplicatedPackages = LocationsPackageSlice{o} + } + + o.R.ReverseReplicatedPackages = related + return nil +} + +// LoadReverseReplicatedPackages loads the locationsPackage's ReverseReplicatedPackages into the .R struct +func (os LocationsPackageSlice) LoadReverseReplicatedPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.ReverseReplicatedPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.ReverseReplicatedPackages = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !rel.ReplicatedPackageID.IsValue() { + continue + } + if !(rel.ReplicatedPackageID.IsValue() && o.UUID == rel.ReplicatedPackageID.MustGet()) { + continue + } + + rel.R.ReverseReplicatedPackages = append(rel.R.ReverseReplicatedPackages, o) + + o.R.ReverseReplicatedPackages = append(o.R.ReverseReplicatedPackages, rel) + } + } + + return nil +} + +// LoadPackageLocationsPackagedownloadtasks loads the locationsPackage's PackageLocationsPackagedownloadtasks into the .R struct +func (o *LocationsPackage) LoadPackageLocationsPackagedownloadtasks(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PackageLocationsPackagedownloadtasks = nil + + related, err := o.PackageLocationsPackagedownloadtasks(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PackageLocationsPackage = o + } + + o.R.PackageLocationsPackagedownloadtasks = related + return nil +} + +// LoadPackageLocationsPackagedownloadtasks loads the locationsPackage's PackageLocationsPackagedownloadtasks into the .R struct +func (os LocationsPackageSlice) LoadPackageLocationsPackagedownloadtasks(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackagedownloadtasks, err := os.PackageLocationsPackagedownloadtasks(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PackageLocationsPackagedownloadtasks = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackagedownloadtasks { + + if !(o.UUID == rel.PackageID) { + continue + } + + rel.R.PackageLocationsPackage = o + + o.R.PackageLocationsPackagedownloadtasks = append(o.R.PackageLocationsPackagedownloadtasks, rel) + } + } + + return nil +} + +type locationsPackageJoins[Q dialect.Joinable] struct { + typ string + PackageLocationsEvents modAs[Q, locationsEventColumns] + PackageLocationsFiles modAs[Q, locationsFileColumns] + PackageLocationsFixitylogs modAs[Q, locationsFixitylogColumns] + CurrentLocationLocationsLocation modAs[Q, locationsLocationColumns] + OriginPipelineLocationsPipeline modAs[Q, locationsPipelineColumns] + PointerFileLocationLocationsLocation modAs[Q, locationsLocationColumns] + FromPackageLocationsPackageRelatedPackages modAs[Q, locationsPackageRelatedPackageColumns] + ToPackageLocationsPackageRelatedPackages modAs[Q, locationsPackageRelatedPackageColumns] + ReplicatedPackage modAs[Q, locationsPackageColumns] + ReverseReplicatedPackages modAs[Q, locationsPackageColumns] + PackageLocationsPackagedownloadtasks modAs[Q, locationsPackagedownloadtaskColumns] +} + +func (j locationsPackageJoins[Q]) aliasedAs(alias string) locationsPackageJoins[Q] { + return buildLocationsPackageJoins[Q](buildLocationsPackageColumns(alias), j.typ) +} + +func buildLocationsPackageJoins[Q dialect.Joinable](cols locationsPackageColumns, typ string) locationsPackageJoins[Q] { + return locationsPackageJoins[Q]{ + typ: typ, + PackageLocationsEvents: modAs[Q, locationsEventColumns]{ + c: LocationsEvents.Columns, + f: func(to locationsEventColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsEvents.Name().As(to.Alias())).On( + to.PackageID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + PackageLocationsFiles: modAs[Q, locationsFileColumns]{ + c: LocationsFiles.Columns, + f: func(to locationsFileColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsFiles.Name().As(to.Alias())).On( + to.PackageID.EQ(cols.ID), + )) + } + + return mods + }, + }, + PackageLocationsFixitylogs: modAs[Q, locationsFixitylogColumns]{ + c: LocationsFixitylogs.Columns, + f: func(to locationsFixitylogColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsFixitylogs.Name().As(to.Alias())).On( + to.PackageID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + CurrentLocationLocationsLocation: modAs[Q, locationsLocationColumns]{ + c: LocationsLocations.Columns, + f: func(to locationsLocationColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocations.Name().As(to.Alias())).On( + to.UUID.EQ(cols.CurrentLocationID), + )) + } + + return mods + }, + }, + OriginPipelineLocationsPipeline: modAs[Q, locationsPipelineColumns]{ + c: LocationsPipelines.Columns, + f: func(to locationsPipelineColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPipelines.Name().As(to.Alias())).On( + to.UUID.EQ(cols.OriginPipelineID), + )) + } + + return mods + }, + }, + PointerFileLocationLocationsLocation: modAs[Q, locationsLocationColumns]{ + c: LocationsLocations.Columns, + f: func(to locationsLocationColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocations.Name().As(to.Alias())).On( + to.UUID.EQ(cols.PointerFileLocationID), + )) + } + + return mods + }, + }, + FromPackageLocationsPackageRelatedPackages: modAs[Q, locationsPackageRelatedPackageColumns]{ + c: LocationsPackageRelatedPackages.Columns, + f: func(to locationsPackageRelatedPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackageRelatedPackages.Name().As(to.Alias())).On( + to.FromPackageID.EQ(cols.ID), + )) + } + + return mods + }, + }, + ToPackageLocationsPackageRelatedPackages: modAs[Q, locationsPackageRelatedPackageColumns]{ + c: LocationsPackageRelatedPackages.Columns, + f: func(to locationsPackageRelatedPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackageRelatedPackages.Name().As(to.Alias())).On( + to.ToPackageID.EQ(cols.ID), + )) + } + + return mods + }, + }, + ReplicatedPackage: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.UUID.EQ(cols.ReplicatedPackageID), + )) + } + + return mods + }, + }, + ReverseReplicatedPackages: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.ReplicatedPackageID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + PackageLocationsPackagedownloadtasks: modAs[Q, locationsPackagedownloadtaskColumns]{ + c: LocationsPackagedownloadtasks.Columns, + f: func(to locationsPackagedownloadtaskColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackagedownloadtasks.Name().As(to.Alias())).On( + to.PackageID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_package_related_packages.bob.go b/database/mcp/models/locations_package_related_packages.bob.go new file mode 100644 index 0000000..7ff373e --- /dev/null +++ b/database/mcp/models/locations_package_related_packages.bob.go @@ -0,0 +1,787 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsPackageRelatedPackage is an object representing the database table. +type LocationsPackageRelatedPackage struct { + ID int32 `db:"id,pk,autoincr" ` + FromPackageID int32 `db:"from_package_id" ` + ToPackageID int32 `db:"to_package_id" ` + + R locationsPackageRelatedPackageR `db:"-" ` +} + +// LocationsPackageRelatedPackageSlice is an alias for a slice of pointers to LocationsPackageRelatedPackage. +// This should almost always be used instead of []*LocationsPackageRelatedPackage. +type LocationsPackageRelatedPackageSlice []*LocationsPackageRelatedPackage + +// LocationsPackageRelatedPackages contains methods to work with the locations_package_related_packages table +var LocationsPackageRelatedPackages = mysql.NewTablex[*LocationsPackageRelatedPackage, LocationsPackageRelatedPackageSlice, *LocationsPackageRelatedPackageSetter]("locations_package_related_packages", buildLocationsPackageRelatedPackageColumns("locations_package_related_packages"), []string{"id"}, []string{"from_package_id", "to_package_id"}) + +// LocationsPackageRelatedPackagesQuery is a query on the locations_package_related_packages table +type LocationsPackageRelatedPackagesQuery = *mysql.ViewQuery[*LocationsPackageRelatedPackage, LocationsPackageRelatedPackageSlice] + +// locationsPackageRelatedPackageR is where relationships are stored. +type locationsPackageRelatedPackageR struct { + FromPackageLocationsPackage *LocationsPackage // locations_package_re_from_package_id_eab8b60c_fk_locations + ToPackageLocationsPackage *LocationsPackage // locations_package_re_to_package_id_7a32b99c_fk_locations +} + +func buildLocationsPackageRelatedPackageColumns(alias string) locationsPackageRelatedPackageColumns { + return locationsPackageRelatedPackageColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "from_package_id", "to_package_id", + ).WithParent("locations_package_related_packages"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + FromPackageID: mysql.Quote(alias, "from_package_id"), + ToPackageID: mysql.Quote(alias, "to_package_id"), + } +} + +type locationsPackageRelatedPackageColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + FromPackageID mysql.Expression + ToPackageID mysql.Expression +} + +func (c locationsPackageRelatedPackageColumns) Alias() string { + return c.tableAlias +} + +func (locationsPackageRelatedPackageColumns) AliasedAs(alias string) locationsPackageRelatedPackageColumns { + return buildLocationsPackageRelatedPackageColumns(alias) +} + +// LocationsPackageRelatedPackageSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsPackageRelatedPackageSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + FromPackageID omit.Val[int32] `db:"from_package_id" ` + ToPackageID omit.Val[int32] `db:"to_package_id" ` +} + +func (s LocationsPackageRelatedPackageSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.FromPackageID.IsValue() { + vals = append(vals, "from_package_id") + } + if s.ToPackageID.IsValue() { + vals = append(vals, "to_package_id") + } + return vals +} + +func (s LocationsPackageRelatedPackageSetter) Overwrite(t *LocationsPackageRelatedPackage) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.FromPackageID.IsValue() { + t.FromPackageID = s.FromPackageID.MustGet() + } + if s.ToPackageID.IsValue() { + t.ToPackageID = s.ToPackageID.MustGet() + } +} + +func (s *LocationsPackageRelatedPackageSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackageRelatedPackages.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.FromPackageID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.FromPackageID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ToPackageID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ToPackageID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsPackageRelatedPackageSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_package_related_packages")...) +} + +func (s LocationsPackageRelatedPackageSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.FromPackageID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "from_package_id")...), + mysql.Arg(s.FromPackageID), + }}) + } + + if s.ToPackageID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "to_package_id")...), + mysql.Arg(s.ToPackageID), + }}) + } + + return exprs +} + +// FindLocationsPackageRelatedPackage retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsPackageRelatedPackage(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsPackageRelatedPackage, error) { + if len(cols) == 0 { + return LocationsPackageRelatedPackages.Query( + sm.Where(LocationsPackageRelatedPackages.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsPackageRelatedPackages.Query( + sm.Where(LocationsPackageRelatedPackages.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsPackageRelatedPackages.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsPackageRelatedPackageExists checks the presence of a single record by primary key +func LocationsPackageRelatedPackageExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsPackageRelatedPackages.Query( + sm.Where(LocationsPackageRelatedPackages.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsPackageRelatedPackage is retrieved from the database +func (o *LocationsPackageRelatedPackage) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPackageRelatedPackages.AfterSelectHooks.RunHooks(ctx, exec, LocationsPackageRelatedPackageSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsPackageRelatedPackages.AfterInsertHooks.RunHooks(ctx, exec, LocationsPackageRelatedPackageSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsPackageRelatedPackages.AfterUpdateHooks.RunHooks(ctx, exec, LocationsPackageRelatedPackageSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsPackageRelatedPackages.AfterDeleteHooks.RunHooks(ctx, exec, LocationsPackageRelatedPackageSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsPackageRelatedPackage +func (o *LocationsPackageRelatedPackage) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsPackageRelatedPackage) pkEQ() dialect.Expression { + return mysql.Quote("locations_package_related_packages", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsPackageRelatedPackage +func (o *LocationsPackageRelatedPackage) Update(ctx context.Context, exec bob.Executor, s *LocationsPackageRelatedPackageSetter) error { + _, err := LocationsPackageRelatedPackages.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsPackageRelatedPackage record with an executor +func (o *LocationsPackageRelatedPackage) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsPackageRelatedPackages.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsPackageRelatedPackage using the executor +func (o *LocationsPackageRelatedPackage) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsPackageRelatedPackages.Query( + sm.Where(LocationsPackageRelatedPackages.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsPackageRelatedPackageSlice is retrieved from the database +func (o LocationsPackageRelatedPackageSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPackageRelatedPackages.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsPackageRelatedPackages.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsPackageRelatedPackages.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsPackageRelatedPackages.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsPackageRelatedPackageSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_package_related_packages", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsPackageRelatedPackageSlice) copyMatchingRows(from ...*LocationsPackageRelatedPackage) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsPackageRelatedPackageSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackageRelatedPackages.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPackageRelatedPackage: + o.copyMatchingRows(retrieved) + case []*LocationsPackageRelatedPackage: + o.copyMatchingRows(retrieved...) + case LocationsPackageRelatedPackageSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPackageRelatedPackage or a slice of LocationsPackageRelatedPackage + // then run the AfterUpdateHooks on the slice + _, err = LocationsPackageRelatedPackages.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsPackageRelatedPackageSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackageRelatedPackages.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPackageRelatedPackage: + o.copyMatchingRows(retrieved) + case []*LocationsPackageRelatedPackage: + o.copyMatchingRows(retrieved...) + case LocationsPackageRelatedPackageSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPackageRelatedPackage or a slice of LocationsPackageRelatedPackage + // then run the AfterDeleteHooks on the slice + _, err = LocationsPackageRelatedPackages.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsPackageRelatedPackageSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsPackageRelatedPackageSetter) error { + _, err := LocationsPackageRelatedPackages.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsPackageRelatedPackageSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsPackageRelatedPackages.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsPackageRelatedPackageSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsPackageRelatedPackages.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// FromPackageLocationsPackage starts a query for related objects on locations_package +func (o *LocationsPackageRelatedPackage) FromPackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.ID.EQ(mysql.Arg(o.FromPackageID))), + )...) +} + +func (os LocationsPackageRelatedPackageSlice) FromPackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.FromPackageID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// ToPackageLocationsPackage starts a query for related objects on locations_package +func (o *LocationsPackageRelatedPackage) ToPackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.ID.EQ(mysql.Arg(o.ToPackageID))), + )...) +} + +func (os LocationsPackageRelatedPackageSlice) ToPackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ToPackageID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsPackageRelatedPackageFromPackageLocationsPackage0(ctx context.Context, exec bob.Executor, count int, locationsPackageRelatedPackage0 *LocationsPackageRelatedPackage, locationsPackage1 *LocationsPackage) (*LocationsPackageRelatedPackage, error) { + setter := &LocationsPackageRelatedPackageSetter{ + FromPackageID: omit.From(locationsPackage1.ID), + } + + err := locationsPackageRelatedPackage0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackageRelatedPackageFromPackageLocationsPackage0: %w", err) + } + + return locationsPackageRelatedPackage0, nil +} + +func (locationsPackageRelatedPackage0 *LocationsPackageRelatedPackage) InsertFromPackageLocationsPackage(ctx context.Context, exec bob.Executor, related *LocationsPackageSetter) error { + var err error + + locationsPackage1, err := LocationsPackages.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPackageRelatedPackageFromPackageLocationsPackage0(ctx, exec, 1, locationsPackageRelatedPackage0, locationsPackage1) + if err != nil { + return err + } + + locationsPackageRelatedPackage0.R.FromPackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.FromPackageLocationsPackageRelatedPackages = append(locationsPackage1.R.FromPackageLocationsPackageRelatedPackages, locationsPackageRelatedPackage0) + + return nil +} + +func (locationsPackageRelatedPackage0 *LocationsPackageRelatedPackage) AttachFromPackageLocationsPackage(ctx context.Context, exec bob.Executor, locationsPackage1 *LocationsPackage) error { + var err error + + _, err = attachLocationsPackageRelatedPackageFromPackageLocationsPackage0(ctx, exec, 1, locationsPackageRelatedPackage0, locationsPackage1) + if err != nil { + return err + } + + locationsPackageRelatedPackage0.R.FromPackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.FromPackageLocationsPackageRelatedPackages = append(locationsPackage1.R.FromPackageLocationsPackageRelatedPackages, locationsPackageRelatedPackage0) + + return nil +} + +func attachLocationsPackageRelatedPackageToPackageLocationsPackage0(ctx context.Context, exec bob.Executor, count int, locationsPackageRelatedPackage0 *LocationsPackageRelatedPackage, locationsPackage1 *LocationsPackage) (*LocationsPackageRelatedPackage, error) { + setter := &LocationsPackageRelatedPackageSetter{ + ToPackageID: omit.From(locationsPackage1.ID), + } + + err := locationsPackageRelatedPackage0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackageRelatedPackageToPackageLocationsPackage0: %w", err) + } + + return locationsPackageRelatedPackage0, nil +} + +func (locationsPackageRelatedPackage0 *LocationsPackageRelatedPackage) InsertToPackageLocationsPackage(ctx context.Context, exec bob.Executor, related *LocationsPackageSetter) error { + var err error + + locationsPackage1, err := LocationsPackages.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPackageRelatedPackageToPackageLocationsPackage0(ctx, exec, 1, locationsPackageRelatedPackage0, locationsPackage1) + if err != nil { + return err + } + + locationsPackageRelatedPackage0.R.ToPackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.ToPackageLocationsPackageRelatedPackages = append(locationsPackage1.R.ToPackageLocationsPackageRelatedPackages, locationsPackageRelatedPackage0) + + return nil +} + +func (locationsPackageRelatedPackage0 *LocationsPackageRelatedPackage) AttachToPackageLocationsPackage(ctx context.Context, exec bob.Executor, locationsPackage1 *LocationsPackage) error { + var err error + + _, err = attachLocationsPackageRelatedPackageToPackageLocationsPackage0(ctx, exec, 1, locationsPackageRelatedPackage0, locationsPackage1) + if err != nil { + return err + } + + locationsPackageRelatedPackage0.R.ToPackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.ToPackageLocationsPackageRelatedPackages = append(locationsPackage1.R.ToPackageLocationsPackageRelatedPackages, locationsPackageRelatedPackage0) + + return nil +} + +type locationsPackageRelatedPackageWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + FromPackageID mysql.WhereMod[Q, int32] + ToPackageID mysql.WhereMod[Q, int32] +} + +func (locationsPackageRelatedPackageWhere[Q]) AliasedAs(alias string) locationsPackageRelatedPackageWhere[Q] { + return buildLocationsPackageRelatedPackageWhere[Q](buildLocationsPackageRelatedPackageColumns(alias)) +} + +func buildLocationsPackageRelatedPackageWhere[Q mysql.Filterable](cols locationsPackageRelatedPackageColumns) locationsPackageRelatedPackageWhere[Q] { + return locationsPackageRelatedPackageWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + FromPackageID: mysql.Where[Q, int32](cols.FromPackageID), + ToPackageID: mysql.Where[Q, int32](cols.ToPackageID), + } +} + +func (o *LocationsPackageRelatedPackage) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "FromPackageLocationsPackage": + rel, ok := retrieved.(*LocationsPackage) + if !ok { + return fmt.Errorf("locationsPackageRelatedPackage cannot load %T as %q", retrieved, name) + } + + o.R.FromPackageLocationsPackage = rel + + if rel != nil { + rel.R.FromPackageLocationsPackageRelatedPackages = LocationsPackageRelatedPackageSlice{o} + } + return nil + case "ToPackageLocationsPackage": + rel, ok := retrieved.(*LocationsPackage) + if !ok { + return fmt.Errorf("locationsPackageRelatedPackage cannot load %T as %q", retrieved, name) + } + + o.R.ToPackageLocationsPackage = rel + + if rel != nil { + rel.R.ToPackageLocationsPackageRelatedPackages = LocationsPackageRelatedPackageSlice{o} + } + return nil + default: + return fmt.Errorf("locationsPackageRelatedPackage has no relationship %q", name) + } +} + +type locationsPackageRelatedPackagePreloader struct { + FromPackageLocationsPackage func(...mysql.PreloadOption) mysql.Preloader + ToPackageLocationsPackage func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsPackageRelatedPackagePreloader() locationsPackageRelatedPackagePreloader { + return locationsPackageRelatedPackagePreloader{ + FromPackageLocationsPackage: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPackage, LocationsPackageSlice](mysql.PreloadRel{ + Name: "FromPackageLocationsPackage", + Sides: []mysql.PreloadSide{ + { + From: LocationsPackageRelatedPackages, + To: LocationsPackages, + FromColumns: []string{"from_package_id"}, + ToColumns: []string{"id"}, + }, + }, + }, LocationsPackages.Columns.Names(), opts...) + }, + ToPackageLocationsPackage: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPackage, LocationsPackageSlice](mysql.PreloadRel{ + Name: "ToPackageLocationsPackage", + Sides: []mysql.PreloadSide{ + { + From: LocationsPackageRelatedPackages, + To: LocationsPackages, + FromColumns: []string{"to_package_id"}, + ToColumns: []string{"id"}, + }, + }, + }, LocationsPackages.Columns.Names(), opts...) + }, + } +} + +type locationsPackageRelatedPackageThenLoader[Q orm.Loadable] struct { + FromPackageLocationsPackage func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ToPackageLocationsPackage func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsPackageRelatedPackageThenLoader[Q orm.Loadable]() locationsPackageRelatedPackageThenLoader[Q] { + type FromPackageLocationsPackageLoadInterface interface { + LoadFromPackageLocationsPackage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ToPackageLocationsPackageLoadInterface interface { + LoadToPackageLocationsPackage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsPackageRelatedPackageThenLoader[Q]{ + FromPackageLocationsPackage: thenLoadBuilder[Q]( + "FromPackageLocationsPackage", + func(ctx context.Context, exec bob.Executor, retrieved FromPackageLocationsPackageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadFromPackageLocationsPackage(ctx, exec, mods...) + }, + ), + ToPackageLocationsPackage: thenLoadBuilder[Q]( + "ToPackageLocationsPackage", + func(ctx context.Context, exec bob.Executor, retrieved ToPackageLocationsPackageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadToPackageLocationsPackage(ctx, exec, mods...) + }, + ), + } +} + +// LoadFromPackageLocationsPackage loads the locationsPackageRelatedPackage's FromPackageLocationsPackage into the .R struct +func (o *LocationsPackageRelatedPackage) LoadFromPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.FromPackageLocationsPackage = nil + + related, err := o.FromPackageLocationsPackage(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.FromPackageLocationsPackageRelatedPackages = LocationsPackageRelatedPackageSlice{o} + + o.R.FromPackageLocationsPackage = related + return nil +} + +// LoadFromPackageLocationsPackage loads the locationsPackageRelatedPackage's FromPackageLocationsPackage into the .R struct +func (os LocationsPackageRelatedPackageSlice) LoadFromPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.FromPackageLocationsPackage(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !(o.FromPackageID == rel.ID) { + continue + } + + rel.R.FromPackageLocationsPackageRelatedPackages = append(rel.R.FromPackageLocationsPackageRelatedPackages, o) + + o.R.FromPackageLocationsPackage = rel + break + } + } + + return nil +} + +// LoadToPackageLocationsPackage loads the locationsPackageRelatedPackage's ToPackageLocationsPackage into the .R struct +func (o *LocationsPackageRelatedPackage) LoadToPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ToPackageLocationsPackage = nil + + related, err := o.ToPackageLocationsPackage(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.ToPackageLocationsPackageRelatedPackages = LocationsPackageRelatedPackageSlice{o} + + o.R.ToPackageLocationsPackage = related + return nil +} + +// LoadToPackageLocationsPackage loads the locationsPackageRelatedPackage's ToPackageLocationsPackage into the .R struct +func (os LocationsPackageRelatedPackageSlice) LoadToPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.ToPackageLocationsPackage(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !(o.ToPackageID == rel.ID) { + continue + } + + rel.R.ToPackageLocationsPackageRelatedPackages = append(rel.R.ToPackageLocationsPackageRelatedPackages, o) + + o.R.ToPackageLocationsPackage = rel + break + } + } + + return nil +} + +type locationsPackageRelatedPackageJoins[Q dialect.Joinable] struct { + typ string + FromPackageLocationsPackage modAs[Q, locationsPackageColumns] + ToPackageLocationsPackage modAs[Q, locationsPackageColumns] +} + +func (j locationsPackageRelatedPackageJoins[Q]) aliasedAs(alias string) locationsPackageRelatedPackageJoins[Q] { + return buildLocationsPackageRelatedPackageJoins[Q](buildLocationsPackageRelatedPackageColumns(alias), j.typ) +} + +func buildLocationsPackageRelatedPackageJoins[Q dialect.Joinable](cols locationsPackageRelatedPackageColumns, typ string) locationsPackageRelatedPackageJoins[Q] { + return locationsPackageRelatedPackageJoins[Q]{ + typ: typ, + FromPackageLocationsPackage: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.ID.EQ(cols.FromPackageID), + )) + } + + return mods + }, + }, + ToPackageLocationsPackage: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.ID.EQ(cols.ToPackageID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_packagedownloadtask.bob.go b/database/mcp/models/locations_packagedownloadtask.bob.go new file mode 100644 index 0000000..3e221d5 --- /dev/null +++ b/database/mcp/models/locations_packagedownloadtask.bob.go @@ -0,0 +1,879 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsPackagedownloadtask is an object representing the database table. +type LocationsPackagedownloadtask struct { + ID int32 `db:"id,pk,autoincr" ` + UUID string `db:"uuid" ` + DownloadsAttempted int32 `db:"downloads_attempted" ` + DownloadsCompleted int32 `db:"downloads_completed" ` + DownloadCompletionTime null.Val[time.Time] `db:"download_completion_time" ` + PackageID string `db:"package_id" ` + + R locationsPackagedownloadtaskR `db:"-" ` +} + +// LocationsPackagedownloadtaskSlice is an alias for a slice of pointers to LocationsPackagedownloadtask. +// This should almost always be used instead of []*LocationsPackagedownloadtask. +type LocationsPackagedownloadtaskSlice []*LocationsPackagedownloadtask + +// LocationsPackagedownloadtasks contains methods to work with the locations_packagedownloadtask table +var LocationsPackagedownloadtasks = mysql.NewTablex[*LocationsPackagedownloadtask, LocationsPackagedownloadtaskSlice, *LocationsPackagedownloadtaskSetter]("locations_packagedownloadtask", buildLocationsPackagedownloadtaskColumns("locations_packagedownloadtask"), []string{"id"}, []string{"uuid"}) + +// LocationsPackagedownloadtasksQuery is a query on the locations_packagedownloadtask table +type LocationsPackagedownloadtasksQuery = *mysql.ViewQuery[*LocationsPackagedownloadtask, LocationsPackagedownloadtaskSlice] + +// locationsPackagedownloadtaskR is where relationships are stored. +type locationsPackagedownloadtaskR struct { + PackageLocationsPackage *LocationsPackage // locations_packagedow_package_id_488c7751_fk_locations + UUIDLocationsPackagedownloadtaskfiles LocationsPackagedownloadtaskfileSlice // locations_packagedow_task_id_a112c9ea_fk_locations +} + +func buildLocationsPackagedownloadtaskColumns(alias string) locationsPackagedownloadtaskColumns { + return locationsPackagedownloadtaskColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "uuid", "downloads_attempted", "downloads_completed", "download_completion_time", "package_id", + ).WithParent("locations_packagedownloadtask"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UUID: mysql.Quote(alias, "uuid"), + DownloadsAttempted: mysql.Quote(alias, "downloads_attempted"), + DownloadsCompleted: mysql.Quote(alias, "downloads_completed"), + DownloadCompletionTime: mysql.Quote(alias, "download_completion_time"), + PackageID: mysql.Quote(alias, "package_id"), + } +} + +type locationsPackagedownloadtaskColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UUID mysql.Expression + DownloadsAttempted mysql.Expression + DownloadsCompleted mysql.Expression + DownloadCompletionTime mysql.Expression + PackageID mysql.Expression +} + +func (c locationsPackagedownloadtaskColumns) Alias() string { + return c.tableAlias +} + +func (locationsPackagedownloadtaskColumns) AliasedAs(alias string) locationsPackagedownloadtaskColumns { + return buildLocationsPackagedownloadtaskColumns(alias) +} + +// LocationsPackagedownloadtaskSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsPackagedownloadtaskSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UUID omit.Val[string] `db:"uuid" ` + DownloadsAttempted omit.Val[int32] `db:"downloads_attempted" ` + DownloadsCompleted omit.Val[int32] `db:"downloads_completed" ` + DownloadCompletionTime omitnull.Val[time.Time] `db:"download_completion_time" ` + PackageID omit.Val[string] `db:"package_id" ` +} + +func (s LocationsPackagedownloadtaskSetter) SetColumns() []string { + vals := make([]string, 0, 6) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UUID.IsValue() { + vals = append(vals, "uuid") + } + if s.DownloadsAttempted.IsValue() { + vals = append(vals, "downloads_attempted") + } + if s.DownloadsCompleted.IsValue() { + vals = append(vals, "downloads_completed") + } + if !s.DownloadCompletionTime.IsUnset() { + vals = append(vals, "download_completion_time") + } + if s.PackageID.IsValue() { + vals = append(vals, "package_id") + } + return vals +} + +func (s LocationsPackagedownloadtaskSetter) Overwrite(t *LocationsPackagedownloadtask) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UUID.IsValue() { + t.UUID = s.UUID.MustGet() + } + if s.DownloadsAttempted.IsValue() { + t.DownloadsAttempted = s.DownloadsAttempted.MustGet() + } + if s.DownloadsCompleted.IsValue() { + t.DownloadsCompleted = s.DownloadsCompleted.MustGet() + } + if !s.DownloadCompletionTime.IsUnset() { + t.DownloadCompletionTime = s.DownloadCompletionTime.MustGetNull() + } + if s.PackageID.IsValue() { + t.PackageID = s.PackageID.MustGet() + } +} + +func (s *LocationsPackagedownloadtaskSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackagedownloadtasks.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UUID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UUID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DownloadsAttempted.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DownloadsAttempted.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DownloadsCompleted.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DownloadsCompleted.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.DownloadCompletionTime.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DownloadCompletionTime.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.PackageID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PackageID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsPackagedownloadtaskSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_packagedownloadtask")...) +} + +func (s LocationsPackagedownloadtaskSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 6) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UUID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uuid")...), + mysql.Arg(s.UUID), + }}) + } + + if s.DownloadsAttempted.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "downloads_attempted")...), + mysql.Arg(s.DownloadsAttempted), + }}) + } + + if s.DownloadsCompleted.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "downloads_completed")...), + mysql.Arg(s.DownloadsCompleted), + }}) + } + + if !s.DownloadCompletionTime.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "download_completion_time")...), + mysql.Arg(s.DownloadCompletionTime), + }}) + } + + if s.PackageID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "package_id")...), + mysql.Arg(s.PackageID), + }}) + } + + return exprs +} + +// FindLocationsPackagedownloadtask retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsPackagedownloadtask(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsPackagedownloadtask, error) { + if len(cols) == 0 { + return LocationsPackagedownloadtasks.Query( + sm.Where(LocationsPackagedownloadtasks.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsPackagedownloadtasks.Query( + sm.Where(LocationsPackagedownloadtasks.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsPackagedownloadtasks.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsPackagedownloadtaskExists checks the presence of a single record by primary key +func LocationsPackagedownloadtaskExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsPackagedownloadtasks.Query( + sm.Where(LocationsPackagedownloadtasks.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsPackagedownloadtask is retrieved from the database +func (o *LocationsPackagedownloadtask) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPackagedownloadtasks.AfterSelectHooks.RunHooks(ctx, exec, LocationsPackagedownloadtaskSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsPackagedownloadtasks.AfterInsertHooks.RunHooks(ctx, exec, LocationsPackagedownloadtaskSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsPackagedownloadtasks.AfterUpdateHooks.RunHooks(ctx, exec, LocationsPackagedownloadtaskSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsPackagedownloadtasks.AfterDeleteHooks.RunHooks(ctx, exec, LocationsPackagedownloadtaskSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsPackagedownloadtask +func (o *LocationsPackagedownloadtask) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsPackagedownloadtask) pkEQ() dialect.Expression { + return mysql.Quote("locations_packagedownloadtask", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsPackagedownloadtask +func (o *LocationsPackagedownloadtask) Update(ctx context.Context, exec bob.Executor, s *LocationsPackagedownloadtaskSetter) error { + _, err := LocationsPackagedownloadtasks.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsPackagedownloadtask record with an executor +func (o *LocationsPackagedownloadtask) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsPackagedownloadtasks.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsPackagedownloadtask using the executor +func (o *LocationsPackagedownloadtask) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsPackagedownloadtasks.Query( + sm.Where(LocationsPackagedownloadtasks.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsPackagedownloadtaskSlice is retrieved from the database +func (o LocationsPackagedownloadtaskSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPackagedownloadtasks.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsPackagedownloadtasks.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsPackagedownloadtasks.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsPackagedownloadtasks.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsPackagedownloadtaskSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_packagedownloadtask", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsPackagedownloadtaskSlice) copyMatchingRows(from ...*LocationsPackagedownloadtask) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsPackagedownloadtaskSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackagedownloadtasks.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPackagedownloadtask: + o.copyMatchingRows(retrieved) + case []*LocationsPackagedownloadtask: + o.copyMatchingRows(retrieved...) + case LocationsPackagedownloadtaskSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPackagedownloadtask or a slice of LocationsPackagedownloadtask + // then run the AfterUpdateHooks on the slice + _, err = LocationsPackagedownloadtasks.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsPackagedownloadtaskSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackagedownloadtasks.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPackagedownloadtask: + o.copyMatchingRows(retrieved) + case []*LocationsPackagedownloadtask: + o.copyMatchingRows(retrieved...) + case LocationsPackagedownloadtaskSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPackagedownloadtask or a slice of LocationsPackagedownloadtask + // then run the AfterDeleteHooks on the slice + _, err = LocationsPackagedownloadtasks.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsPackagedownloadtaskSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsPackagedownloadtaskSetter) error { + _, err := LocationsPackagedownloadtasks.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsPackagedownloadtaskSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsPackagedownloadtasks.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsPackagedownloadtaskSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsPackagedownloadtasks.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// PackageLocationsPackage starts a query for related objects on locations_package +func (o *LocationsPackagedownloadtask) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.UUID.EQ(mysql.Arg(o.PackageID))), + )...) +} + +func (os LocationsPackagedownloadtaskSlice) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PackageID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +// UUIDLocationsPackagedownloadtaskfiles starts a query for related objects on locations_packagedownloadtaskfile +func (o *LocationsPackagedownloadtask) UUIDLocationsPackagedownloadtaskfiles(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagedownloadtaskfilesQuery { + return LocationsPackagedownloadtaskfiles.Query(append(mods, + sm.Where(LocationsPackagedownloadtaskfiles.Columns.TaskID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsPackagedownloadtaskSlice) UUIDLocationsPackagedownloadtaskfiles(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagedownloadtaskfilesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackagedownloadtaskfiles.Query(append(mods, + sm.Where(mysql.Group(LocationsPackagedownloadtaskfiles.Columns.TaskID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsPackagedownloadtaskPackageLocationsPackage0(ctx context.Context, exec bob.Executor, count int, locationsPackagedownloadtask0 *LocationsPackagedownloadtask, locationsPackage1 *LocationsPackage) (*LocationsPackagedownloadtask, error) { + setter := &LocationsPackagedownloadtaskSetter{ + PackageID: omit.From(locationsPackage1.UUID), + } + + err := locationsPackagedownloadtask0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackagedownloadtaskPackageLocationsPackage0: %w", err) + } + + return locationsPackagedownloadtask0, nil +} + +func (locationsPackagedownloadtask0 *LocationsPackagedownloadtask) InsertPackageLocationsPackage(ctx context.Context, exec bob.Executor, related *LocationsPackageSetter) error { + var err error + + locationsPackage1, err := LocationsPackages.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPackagedownloadtaskPackageLocationsPackage0(ctx, exec, 1, locationsPackagedownloadtask0, locationsPackage1) + if err != nil { + return err + } + + locationsPackagedownloadtask0.R.PackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.PackageLocationsPackagedownloadtasks = append(locationsPackage1.R.PackageLocationsPackagedownloadtasks, locationsPackagedownloadtask0) + + return nil +} + +func (locationsPackagedownloadtask0 *LocationsPackagedownloadtask) AttachPackageLocationsPackage(ctx context.Context, exec bob.Executor, locationsPackage1 *LocationsPackage) error { + var err error + + _, err = attachLocationsPackagedownloadtaskPackageLocationsPackage0(ctx, exec, 1, locationsPackagedownloadtask0, locationsPackage1) + if err != nil { + return err + } + + locationsPackagedownloadtask0.R.PackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.PackageLocationsPackagedownloadtasks = append(locationsPackage1.R.PackageLocationsPackagedownloadtasks, locationsPackagedownloadtask0) + + return nil +} + +func insertLocationsPackagedownloadtaskUUIDLocationsPackagedownloadtaskfiles0(ctx context.Context, exec bob.Executor, locationsPackagedownloadtaskfiles1 []*LocationsPackagedownloadtaskfileSetter, locationsPackagedownloadtask0 *LocationsPackagedownloadtask) (LocationsPackagedownloadtaskfileSlice, error) { + for i := range locationsPackagedownloadtaskfiles1 { + locationsPackagedownloadtaskfiles1[i].TaskID = omit.From(locationsPackagedownloadtask0.UUID) + } + + ret, err := LocationsPackagedownloadtaskfiles.Insert(bob.ToMods(locationsPackagedownloadtaskfiles1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPackagedownloadtaskUUIDLocationsPackagedownloadtaskfiles0: %w", err) + } + + return ret, nil +} + +func attachLocationsPackagedownloadtaskUUIDLocationsPackagedownloadtaskfiles0(ctx context.Context, exec bob.Executor, count int, locationsPackagedownloadtaskfiles1 LocationsPackagedownloadtaskfileSlice, locationsPackagedownloadtask0 *LocationsPackagedownloadtask) (LocationsPackagedownloadtaskfileSlice, error) { + setter := &LocationsPackagedownloadtaskfileSetter{ + TaskID: omit.From(locationsPackagedownloadtask0.UUID), + } + + err := locationsPackagedownloadtaskfiles1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackagedownloadtaskUUIDLocationsPackagedownloadtaskfiles0: %w", err) + } + + return locationsPackagedownloadtaskfiles1, nil +} + +func (locationsPackagedownloadtask0 *LocationsPackagedownloadtask) InsertUUIDLocationsPackagedownloadtaskfiles(ctx context.Context, exec bob.Executor, related ...*LocationsPackagedownloadtaskfileSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsPackagedownloadtaskfiles1, err := insertLocationsPackagedownloadtaskUUIDLocationsPackagedownloadtaskfiles0(ctx, exec, related, locationsPackagedownloadtask0) + if err != nil { + return err + } + + locationsPackagedownloadtask0.R.UUIDLocationsPackagedownloadtaskfiles = append(locationsPackagedownloadtask0.R.UUIDLocationsPackagedownloadtaskfiles, locationsPackagedownloadtaskfiles1...) + + for _, rel := range locationsPackagedownloadtaskfiles1 { + rel.R.TaskLocationsPackagedownloadtask = locationsPackagedownloadtask0 + } + return nil +} + +func (locationsPackagedownloadtask0 *LocationsPackagedownloadtask) AttachUUIDLocationsPackagedownloadtaskfiles(ctx context.Context, exec bob.Executor, related ...*LocationsPackagedownloadtaskfile) error { + if len(related) == 0 { + return nil + } + + var err error + locationsPackagedownloadtaskfiles1 := LocationsPackagedownloadtaskfileSlice(related) + + _, err = attachLocationsPackagedownloadtaskUUIDLocationsPackagedownloadtaskfiles0(ctx, exec, len(related), locationsPackagedownloadtaskfiles1, locationsPackagedownloadtask0) + if err != nil { + return err + } + + locationsPackagedownloadtask0.R.UUIDLocationsPackagedownloadtaskfiles = append(locationsPackagedownloadtask0.R.UUIDLocationsPackagedownloadtaskfiles, locationsPackagedownloadtaskfiles1...) + + for _, rel := range related { + rel.R.TaskLocationsPackagedownloadtask = locationsPackagedownloadtask0 + } + + return nil +} + +type locationsPackagedownloadtaskWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UUID mysql.WhereMod[Q, string] + DownloadsAttempted mysql.WhereMod[Q, int32] + DownloadsCompleted mysql.WhereMod[Q, int32] + DownloadCompletionTime mysql.WhereNullMod[Q, time.Time] + PackageID mysql.WhereMod[Q, string] +} + +func (locationsPackagedownloadtaskWhere[Q]) AliasedAs(alias string) locationsPackagedownloadtaskWhere[Q] { + return buildLocationsPackagedownloadtaskWhere[Q](buildLocationsPackagedownloadtaskColumns(alias)) +} + +func buildLocationsPackagedownloadtaskWhere[Q mysql.Filterable](cols locationsPackagedownloadtaskColumns) locationsPackagedownloadtaskWhere[Q] { + return locationsPackagedownloadtaskWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UUID: mysql.Where[Q, string](cols.UUID), + DownloadsAttempted: mysql.Where[Q, int32](cols.DownloadsAttempted), + DownloadsCompleted: mysql.Where[Q, int32](cols.DownloadsCompleted), + DownloadCompletionTime: mysql.WhereNull[Q, time.Time](cols.DownloadCompletionTime), + PackageID: mysql.Where[Q, string](cols.PackageID), + } +} + +func (o *LocationsPackagedownloadtask) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "PackageLocationsPackage": + rel, ok := retrieved.(*LocationsPackage) + if !ok { + return fmt.Errorf("locationsPackagedownloadtask cannot load %T as %q", retrieved, name) + } + + o.R.PackageLocationsPackage = rel + + if rel != nil { + rel.R.PackageLocationsPackagedownloadtasks = LocationsPackagedownloadtaskSlice{o} + } + return nil + case "UUIDLocationsPackagedownloadtaskfiles": + rels, ok := retrieved.(LocationsPackagedownloadtaskfileSlice) + if !ok { + return fmt.Errorf("locationsPackagedownloadtask cannot load %T as %q", retrieved, name) + } + + o.R.UUIDLocationsPackagedownloadtaskfiles = rels + + for _, rel := range rels { + if rel != nil { + rel.R.TaskLocationsPackagedownloadtask = o + } + } + return nil + default: + return fmt.Errorf("locationsPackagedownloadtask has no relationship %q", name) + } +} + +type locationsPackagedownloadtaskPreloader struct { + PackageLocationsPackage func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsPackagedownloadtaskPreloader() locationsPackagedownloadtaskPreloader { + return locationsPackagedownloadtaskPreloader{ + PackageLocationsPackage: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPackage, LocationsPackageSlice](mysql.PreloadRel{ + Name: "PackageLocationsPackage", + Sides: []mysql.PreloadSide{ + { + From: LocationsPackagedownloadtasks, + To: LocationsPackages, + FromColumns: []string{"package_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsPackages.Columns.Names(), opts...) + }, + } +} + +type locationsPackagedownloadtaskThenLoader[Q orm.Loadable] struct { + PackageLocationsPackage func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + UUIDLocationsPackagedownloadtaskfiles func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsPackagedownloadtaskThenLoader[Q orm.Loadable]() locationsPackagedownloadtaskThenLoader[Q] { + type PackageLocationsPackageLoadInterface interface { + LoadPackageLocationsPackage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type UUIDLocationsPackagedownloadtaskfilesLoadInterface interface { + LoadUUIDLocationsPackagedownloadtaskfiles(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsPackagedownloadtaskThenLoader[Q]{ + PackageLocationsPackage: thenLoadBuilder[Q]( + "PackageLocationsPackage", + func(ctx context.Context, exec bob.Executor, retrieved PackageLocationsPackageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPackageLocationsPackage(ctx, exec, mods...) + }, + ), + UUIDLocationsPackagedownloadtaskfiles: thenLoadBuilder[Q]( + "UUIDLocationsPackagedownloadtaskfiles", + func(ctx context.Context, exec bob.Executor, retrieved UUIDLocationsPackagedownloadtaskfilesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUUIDLocationsPackagedownloadtaskfiles(ctx, exec, mods...) + }, + ), + } +} + +// LoadPackageLocationsPackage loads the locationsPackagedownloadtask's PackageLocationsPackage into the .R struct +func (o *LocationsPackagedownloadtask) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PackageLocationsPackage = nil + + related, err := o.PackageLocationsPackage(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PackageLocationsPackagedownloadtasks = LocationsPackagedownloadtaskSlice{o} + + o.R.PackageLocationsPackage = related + return nil +} + +// LoadPackageLocationsPackage loads the locationsPackagedownloadtask's PackageLocationsPackage into the .R struct +func (os LocationsPackagedownloadtaskSlice) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.PackageLocationsPackage(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !(o.PackageID == rel.UUID) { + continue + } + + rel.R.PackageLocationsPackagedownloadtasks = append(rel.R.PackageLocationsPackagedownloadtasks, o) + + o.R.PackageLocationsPackage = rel + break + } + } + + return nil +} + +// LoadUUIDLocationsPackagedownloadtaskfiles loads the locationsPackagedownloadtask's UUIDLocationsPackagedownloadtaskfiles into the .R struct +func (o *LocationsPackagedownloadtask) LoadUUIDLocationsPackagedownloadtaskfiles(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UUIDLocationsPackagedownloadtaskfiles = nil + + related, err := o.UUIDLocationsPackagedownloadtaskfiles(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.TaskLocationsPackagedownloadtask = o + } + + o.R.UUIDLocationsPackagedownloadtaskfiles = related + return nil +} + +// LoadUUIDLocationsPackagedownloadtaskfiles loads the locationsPackagedownloadtask's UUIDLocationsPackagedownloadtaskfiles into the .R struct +func (os LocationsPackagedownloadtaskSlice) LoadUUIDLocationsPackagedownloadtaskfiles(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackagedownloadtaskfiles, err := os.UUIDLocationsPackagedownloadtaskfiles(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.UUIDLocationsPackagedownloadtaskfiles = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackagedownloadtaskfiles { + + if !(o.UUID == rel.TaskID) { + continue + } + + rel.R.TaskLocationsPackagedownloadtask = o + + o.R.UUIDLocationsPackagedownloadtaskfiles = append(o.R.UUIDLocationsPackagedownloadtaskfiles, rel) + } + } + + return nil +} + +type locationsPackagedownloadtaskJoins[Q dialect.Joinable] struct { + typ string + PackageLocationsPackage modAs[Q, locationsPackageColumns] + UUIDLocationsPackagedownloadtaskfiles modAs[Q, locationsPackagedownloadtaskfileColumns] +} + +func (j locationsPackagedownloadtaskJoins[Q]) aliasedAs(alias string) locationsPackagedownloadtaskJoins[Q] { + return buildLocationsPackagedownloadtaskJoins[Q](buildLocationsPackagedownloadtaskColumns(alias), j.typ) +} + +func buildLocationsPackagedownloadtaskJoins[Q dialect.Joinable](cols locationsPackagedownloadtaskColumns, typ string) locationsPackagedownloadtaskJoins[Q] { + return locationsPackagedownloadtaskJoins[Q]{ + typ: typ, + PackageLocationsPackage: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.UUID.EQ(cols.PackageID), + )) + } + + return mods + }, + }, + UUIDLocationsPackagedownloadtaskfiles: modAs[Q, locationsPackagedownloadtaskfileColumns]{ + c: LocationsPackagedownloadtaskfiles.Columns, + f: func(to locationsPackagedownloadtaskfileColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackagedownloadtaskfiles.Name().As(to.Alias())).On( + to.TaskID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_packagedownloadtaskfile.bob.go b/database/mcp/models/locations_packagedownloadtaskfile.bob.go new file mode 100644 index 0000000..79cc2ba --- /dev/null +++ b/database/mcp/models/locations_packagedownloadtaskfile.bob.go @@ -0,0 +1,712 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsPackagedownloadtaskfile is an object representing the database table. +type LocationsPackagedownloadtaskfile struct { + ID int32 `db:"id,pk,autoincr" ` + UUID string `db:"uuid" ` + Filename string `db:"filename" ` + URL string `db:"url" ` + Completed bool `db:"completed" ` + Failed bool `db:"failed" ` + TaskID string `db:"task_id" ` + + R locationsPackagedownloadtaskfileR `db:"-" ` +} + +// LocationsPackagedownloadtaskfileSlice is an alias for a slice of pointers to LocationsPackagedownloadtaskfile. +// This should almost always be used instead of []*LocationsPackagedownloadtaskfile. +type LocationsPackagedownloadtaskfileSlice []*LocationsPackagedownloadtaskfile + +// LocationsPackagedownloadtaskfiles contains methods to work with the locations_packagedownloadtaskfile table +var LocationsPackagedownloadtaskfiles = mysql.NewTablex[*LocationsPackagedownloadtaskfile, LocationsPackagedownloadtaskfileSlice, *LocationsPackagedownloadtaskfileSetter]("locations_packagedownloadtaskfile", buildLocationsPackagedownloadtaskfileColumns("locations_packagedownloadtaskfile"), []string{"id"}, []string{"uuid"}) + +// LocationsPackagedownloadtaskfilesQuery is a query on the locations_packagedownloadtaskfile table +type LocationsPackagedownloadtaskfilesQuery = *mysql.ViewQuery[*LocationsPackagedownloadtaskfile, LocationsPackagedownloadtaskfileSlice] + +// locationsPackagedownloadtaskfileR is where relationships are stored. +type locationsPackagedownloadtaskfileR struct { + TaskLocationsPackagedownloadtask *LocationsPackagedownloadtask // locations_packagedow_task_id_a112c9ea_fk_locations +} + +func buildLocationsPackagedownloadtaskfileColumns(alias string) locationsPackagedownloadtaskfileColumns { + return locationsPackagedownloadtaskfileColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "uuid", "filename", "url", "completed", "failed", "task_id", + ).WithParent("locations_packagedownloadtaskfile"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UUID: mysql.Quote(alias, "uuid"), + Filename: mysql.Quote(alias, "filename"), + URL: mysql.Quote(alias, "url"), + Completed: mysql.Quote(alias, "completed"), + Failed: mysql.Quote(alias, "failed"), + TaskID: mysql.Quote(alias, "task_id"), + } +} + +type locationsPackagedownloadtaskfileColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UUID mysql.Expression + Filename mysql.Expression + URL mysql.Expression + Completed mysql.Expression + Failed mysql.Expression + TaskID mysql.Expression +} + +func (c locationsPackagedownloadtaskfileColumns) Alias() string { + return c.tableAlias +} + +func (locationsPackagedownloadtaskfileColumns) AliasedAs(alias string) locationsPackagedownloadtaskfileColumns { + return buildLocationsPackagedownloadtaskfileColumns(alias) +} + +// LocationsPackagedownloadtaskfileSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsPackagedownloadtaskfileSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UUID omit.Val[string] `db:"uuid" ` + Filename omit.Val[string] `db:"filename" ` + URL omit.Val[string] `db:"url" ` + Completed omit.Val[bool] `db:"completed" ` + Failed omit.Val[bool] `db:"failed" ` + TaskID omit.Val[string] `db:"task_id" ` +} + +func (s LocationsPackagedownloadtaskfileSetter) SetColumns() []string { + vals := make([]string, 0, 7) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UUID.IsValue() { + vals = append(vals, "uuid") + } + if s.Filename.IsValue() { + vals = append(vals, "filename") + } + if s.URL.IsValue() { + vals = append(vals, "url") + } + if s.Completed.IsValue() { + vals = append(vals, "completed") + } + if s.Failed.IsValue() { + vals = append(vals, "failed") + } + if s.TaskID.IsValue() { + vals = append(vals, "task_id") + } + return vals +} + +func (s LocationsPackagedownloadtaskfileSetter) Overwrite(t *LocationsPackagedownloadtaskfile) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UUID.IsValue() { + t.UUID = s.UUID.MustGet() + } + if s.Filename.IsValue() { + t.Filename = s.Filename.MustGet() + } + if s.URL.IsValue() { + t.URL = s.URL.MustGet() + } + if s.Completed.IsValue() { + t.Completed = s.Completed.MustGet() + } + if s.Failed.IsValue() { + t.Failed = s.Failed.MustGet() + } + if s.TaskID.IsValue() { + t.TaskID = s.TaskID.MustGet() + } +} + +func (s *LocationsPackagedownloadtaskfileSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackagedownloadtaskfiles.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UUID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UUID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Filename.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Filename.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.URL.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.URL.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Completed.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Completed.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Failed.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Failed.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.TaskID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.TaskID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsPackagedownloadtaskfileSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_packagedownloadtaskfile")...) +} + +func (s LocationsPackagedownloadtaskfileSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 7) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UUID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uuid")...), + mysql.Arg(s.UUID), + }}) + } + + if s.Filename.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "filename")...), + mysql.Arg(s.Filename), + }}) + } + + if s.URL.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "url")...), + mysql.Arg(s.URL), + }}) + } + + if s.Completed.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "completed")...), + mysql.Arg(s.Completed), + }}) + } + + if s.Failed.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "failed")...), + mysql.Arg(s.Failed), + }}) + } + + if s.TaskID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "task_id")...), + mysql.Arg(s.TaskID), + }}) + } + + return exprs +} + +// FindLocationsPackagedownloadtaskfile retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsPackagedownloadtaskfile(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsPackagedownloadtaskfile, error) { + if len(cols) == 0 { + return LocationsPackagedownloadtaskfiles.Query( + sm.Where(LocationsPackagedownloadtaskfiles.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsPackagedownloadtaskfiles.Query( + sm.Where(LocationsPackagedownloadtaskfiles.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsPackagedownloadtaskfiles.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsPackagedownloadtaskfileExists checks the presence of a single record by primary key +func LocationsPackagedownloadtaskfileExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsPackagedownloadtaskfiles.Query( + sm.Where(LocationsPackagedownloadtaskfiles.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsPackagedownloadtaskfile is retrieved from the database +func (o *LocationsPackagedownloadtaskfile) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPackagedownloadtaskfiles.AfterSelectHooks.RunHooks(ctx, exec, LocationsPackagedownloadtaskfileSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsPackagedownloadtaskfiles.AfterInsertHooks.RunHooks(ctx, exec, LocationsPackagedownloadtaskfileSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsPackagedownloadtaskfiles.AfterUpdateHooks.RunHooks(ctx, exec, LocationsPackagedownloadtaskfileSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsPackagedownloadtaskfiles.AfterDeleteHooks.RunHooks(ctx, exec, LocationsPackagedownloadtaskfileSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsPackagedownloadtaskfile +func (o *LocationsPackagedownloadtaskfile) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsPackagedownloadtaskfile) pkEQ() dialect.Expression { + return mysql.Quote("locations_packagedownloadtaskfile", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsPackagedownloadtaskfile +func (o *LocationsPackagedownloadtaskfile) Update(ctx context.Context, exec bob.Executor, s *LocationsPackagedownloadtaskfileSetter) error { + _, err := LocationsPackagedownloadtaskfiles.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsPackagedownloadtaskfile record with an executor +func (o *LocationsPackagedownloadtaskfile) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsPackagedownloadtaskfiles.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsPackagedownloadtaskfile using the executor +func (o *LocationsPackagedownloadtaskfile) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsPackagedownloadtaskfiles.Query( + sm.Where(LocationsPackagedownloadtaskfiles.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsPackagedownloadtaskfileSlice is retrieved from the database +func (o LocationsPackagedownloadtaskfileSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPackagedownloadtaskfiles.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsPackagedownloadtaskfiles.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsPackagedownloadtaskfiles.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsPackagedownloadtaskfiles.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsPackagedownloadtaskfileSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_packagedownloadtaskfile", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsPackagedownloadtaskfileSlice) copyMatchingRows(from ...*LocationsPackagedownloadtaskfile) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsPackagedownloadtaskfileSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackagedownloadtaskfiles.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPackagedownloadtaskfile: + o.copyMatchingRows(retrieved) + case []*LocationsPackagedownloadtaskfile: + o.copyMatchingRows(retrieved...) + case LocationsPackagedownloadtaskfileSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPackagedownloadtaskfile or a slice of LocationsPackagedownloadtaskfile + // then run the AfterUpdateHooks on the slice + _, err = LocationsPackagedownloadtaskfiles.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsPackagedownloadtaskfileSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackagedownloadtaskfiles.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPackagedownloadtaskfile: + o.copyMatchingRows(retrieved) + case []*LocationsPackagedownloadtaskfile: + o.copyMatchingRows(retrieved...) + case LocationsPackagedownloadtaskfileSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPackagedownloadtaskfile or a slice of LocationsPackagedownloadtaskfile + // then run the AfterDeleteHooks on the slice + _, err = LocationsPackagedownloadtaskfiles.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsPackagedownloadtaskfileSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsPackagedownloadtaskfileSetter) error { + _, err := LocationsPackagedownloadtaskfiles.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsPackagedownloadtaskfileSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsPackagedownloadtaskfiles.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsPackagedownloadtaskfileSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsPackagedownloadtaskfiles.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// TaskLocationsPackagedownloadtask starts a query for related objects on locations_packagedownloadtask +func (o *LocationsPackagedownloadtaskfile) TaskLocationsPackagedownloadtask(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagedownloadtasksQuery { + return LocationsPackagedownloadtasks.Query(append(mods, + sm.Where(LocationsPackagedownloadtasks.Columns.UUID.EQ(mysql.Arg(o.TaskID))), + )...) +} + +func (os LocationsPackagedownloadtaskfileSlice) TaskLocationsPackagedownloadtask(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagedownloadtasksQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.TaskID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackagedownloadtasks.Query(append(mods, + sm.Where(mysql.Group(LocationsPackagedownloadtasks.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsPackagedownloadtaskfileTaskLocationsPackagedownloadtask0(ctx context.Context, exec bob.Executor, count int, locationsPackagedownloadtaskfile0 *LocationsPackagedownloadtaskfile, locationsPackagedownloadtask1 *LocationsPackagedownloadtask) (*LocationsPackagedownloadtaskfile, error) { + setter := &LocationsPackagedownloadtaskfileSetter{ + TaskID: omit.From(locationsPackagedownloadtask1.UUID), + } + + err := locationsPackagedownloadtaskfile0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackagedownloadtaskfileTaskLocationsPackagedownloadtask0: %w", err) + } + + return locationsPackagedownloadtaskfile0, nil +} + +func (locationsPackagedownloadtaskfile0 *LocationsPackagedownloadtaskfile) InsertTaskLocationsPackagedownloadtask(ctx context.Context, exec bob.Executor, related *LocationsPackagedownloadtaskSetter) error { + var err error + + locationsPackagedownloadtask1, err := LocationsPackagedownloadtasks.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPackagedownloadtaskfileTaskLocationsPackagedownloadtask0(ctx, exec, 1, locationsPackagedownloadtaskfile0, locationsPackagedownloadtask1) + if err != nil { + return err + } + + locationsPackagedownloadtaskfile0.R.TaskLocationsPackagedownloadtask = locationsPackagedownloadtask1 + + locationsPackagedownloadtask1.R.UUIDLocationsPackagedownloadtaskfiles = append(locationsPackagedownloadtask1.R.UUIDLocationsPackagedownloadtaskfiles, locationsPackagedownloadtaskfile0) + + return nil +} + +func (locationsPackagedownloadtaskfile0 *LocationsPackagedownloadtaskfile) AttachTaskLocationsPackagedownloadtask(ctx context.Context, exec bob.Executor, locationsPackagedownloadtask1 *LocationsPackagedownloadtask) error { + var err error + + _, err = attachLocationsPackagedownloadtaskfileTaskLocationsPackagedownloadtask0(ctx, exec, 1, locationsPackagedownloadtaskfile0, locationsPackagedownloadtask1) + if err != nil { + return err + } + + locationsPackagedownloadtaskfile0.R.TaskLocationsPackagedownloadtask = locationsPackagedownloadtask1 + + locationsPackagedownloadtask1.R.UUIDLocationsPackagedownloadtaskfiles = append(locationsPackagedownloadtask1.R.UUIDLocationsPackagedownloadtaskfiles, locationsPackagedownloadtaskfile0) + + return nil +} + +type locationsPackagedownloadtaskfileWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UUID mysql.WhereMod[Q, string] + Filename mysql.WhereMod[Q, string] + URL mysql.WhereMod[Q, string] + Completed mysql.WhereMod[Q, bool] + Failed mysql.WhereMod[Q, bool] + TaskID mysql.WhereMod[Q, string] +} + +func (locationsPackagedownloadtaskfileWhere[Q]) AliasedAs(alias string) locationsPackagedownloadtaskfileWhere[Q] { + return buildLocationsPackagedownloadtaskfileWhere[Q](buildLocationsPackagedownloadtaskfileColumns(alias)) +} + +func buildLocationsPackagedownloadtaskfileWhere[Q mysql.Filterable](cols locationsPackagedownloadtaskfileColumns) locationsPackagedownloadtaskfileWhere[Q] { + return locationsPackagedownloadtaskfileWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UUID: mysql.Where[Q, string](cols.UUID), + Filename: mysql.Where[Q, string](cols.Filename), + URL: mysql.Where[Q, string](cols.URL), + Completed: mysql.Where[Q, bool](cols.Completed), + Failed: mysql.Where[Q, bool](cols.Failed), + TaskID: mysql.Where[Q, string](cols.TaskID), + } +} + +func (o *LocationsPackagedownloadtaskfile) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "TaskLocationsPackagedownloadtask": + rel, ok := retrieved.(*LocationsPackagedownloadtask) + if !ok { + return fmt.Errorf("locationsPackagedownloadtaskfile cannot load %T as %q", retrieved, name) + } + + o.R.TaskLocationsPackagedownloadtask = rel + + if rel != nil { + rel.R.UUIDLocationsPackagedownloadtaskfiles = LocationsPackagedownloadtaskfileSlice{o} + } + return nil + default: + return fmt.Errorf("locationsPackagedownloadtaskfile has no relationship %q", name) + } +} + +type locationsPackagedownloadtaskfilePreloader struct { + TaskLocationsPackagedownloadtask func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsPackagedownloadtaskfilePreloader() locationsPackagedownloadtaskfilePreloader { + return locationsPackagedownloadtaskfilePreloader{ + TaskLocationsPackagedownloadtask: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPackagedownloadtask, LocationsPackagedownloadtaskSlice](mysql.PreloadRel{ + Name: "TaskLocationsPackagedownloadtask", + Sides: []mysql.PreloadSide{ + { + From: LocationsPackagedownloadtaskfiles, + To: LocationsPackagedownloadtasks, + FromColumns: []string{"task_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsPackagedownloadtasks.Columns.Names(), opts...) + }, + } +} + +type locationsPackagedownloadtaskfileThenLoader[Q orm.Loadable] struct { + TaskLocationsPackagedownloadtask func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsPackagedownloadtaskfileThenLoader[Q orm.Loadable]() locationsPackagedownloadtaskfileThenLoader[Q] { + type TaskLocationsPackagedownloadtaskLoadInterface interface { + LoadTaskLocationsPackagedownloadtask(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsPackagedownloadtaskfileThenLoader[Q]{ + TaskLocationsPackagedownloadtask: thenLoadBuilder[Q]( + "TaskLocationsPackagedownloadtask", + func(ctx context.Context, exec bob.Executor, retrieved TaskLocationsPackagedownloadtaskLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadTaskLocationsPackagedownloadtask(ctx, exec, mods...) + }, + ), + } +} + +// LoadTaskLocationsPackagedownloadtask loads the locationsPackagedownloadtaskfile's TaskLocationsPackagedownloadtask into the .R struct +func (o *LocationsPackagedownloadtaskfile) LoadTaskLocationsPackagedownloadtask(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.TaskLocationsPackagedownloadtask = nil + + related, err := o.TaskLocationsPackagedownloadtask(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.UUIDLocationsPackagedownloadtaskfiles = LocationsPackagedownloadtaskfileSlice{o} + + o.R.TaskLocationsPackagedownloadtask = related + return nil +} + +// LoadTaskLocationsPackagedownloadtask loads the locationsPackagedownloadtaskfile's TaskLocationsPackagedownloadtask into the .R struct +func (os LocationsPackagedownloadtaskfileSlice) LoadTaskLocationsPackagedownloadtask(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackagedownloadtasks, err := os.TaskLocationsPackagedownloadtask(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackagedownloadtasks { + + if !(o.TaskID == rel.UUID) { + continue + } + + rel.R.UUIDLocationsPackagedownloadtaskfiles = append(rel.R.UUIDLocationsPackagedownloadtaskfiles, o) + + o.R.TaskLocationsPackagedownloadtask = rel + break + } + } + + return nil +} + +type locationsPackagedownloadtaskfileJoins[Q dialect.Joinable] struct { + typ string + TaskLocationsPackagedownloadtask modAs[Q, locationsPackagedownloadtaskColumns] +} + +func (j locationsPackagedownloadtaskfileJoins[Q]) aliasedAs(alias string) locationsPackagedownloadtaskfileJoins[Q] { + return buildLocationsPackagedownloadtaskfileJoins[Q](buildLocationsPackagedownloadtaskfileColumns(alias), j.typ) +} + +func buildLocationsPackagedownloadtaskfileJoins[Q dialect.Joinable](cols locationsPackagedownloadtaskfileColumns, typ string) locationsPackagedownloadtaskfileJoins[Q] { + return locationsPackagedownloadtaskfileJoins[Q]{ + typ: typ, + TaskLocationsPackagedownloadtask: modAs[Q, locationsPackagedownloadtaskColumns]{ + c: LocationsPackagedownloadtasks.Columns, + f: func(to locationsPackagedownloadtaskColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackagedownloadtasks.Name().As(to.Alias())).On( + to.UUID.EQ(cols.TaskID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_pipeline.bob.go b/database/mcp/models/locations_pipeline.bob.go new file mode 100644 index 0000000..6b8d97a --- /dev/null +++ b/database/mcp/models/locations_pipeline.bob.go @@ -0,0 +1,1108 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsPipeline is an object representing the database table. +type LocationsPipeline struct { + ID int32 `db:"id,pk,autoincr" ` + UUID string `db:"uuid" ` + Description null.Val[string] `db:"description" ` + Enabled bool `db:"enabled" ` + APIKey null.Val[string] `db:"api_key" ` + APIUsername null.Val[string] `db:"api_username" ` + RemoteName null.Val[string] `db:"remote_name" ` + + R locationsPipelineR `db:"-" ` +} + +// LocationsPipelineSlice is an alias for a slice of pointers to LocationsPipeline. +// This should almost always be used instead of []*LocationsPipeline. +type LocationsPipelineSlice []*LocationsPipeline + +// LocationsPipelines contains methods to work with the locations_pipeline table +var LocationsPipelines = mysql.NewTablex[*LocationsPipeline, LocationsPipelineSlice, *LocationsPipelineSetter]("locations_pipeline", buildLocationsPipelineColumns("locations_pipeline"), []string{"id"}, []string{"uuid"}) + +// LocationsPipelinesQuery is a query on the locations_pipeline table +type LocationsPipelinesQuery = *mysql.ViewQuery[*LocationsPipeline, LocationsPipelineSlice] + +// locationsPipelineR is where relationships are stored. +type locationsPipelineR struct { + PipelineLocationsEvents LocationsEventSlice // locations_event_pipeline_id_5188361f_fk_locations_pipeline_uuid + PipelineLocationsLocationpipelines LocationsLocationpipelineSlice // locations_locationpi_pipeline_id_2ad721b4_fk_locations + OriginPipelineLocationsPackages LocationsPackageSlice // locations_package_origin_pipeline_id_9f8d6473_fk_locations +} + +func buildLocationsPipelineColumns(alias string) locationsPipelineColumns { + return locationsPipelineColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "uuid", "description", "enabled", "api_key", "api_username", "remote_name", + ).WithParent("locations_pipeline"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UUID: mysql.Quote(alias, "uuid"), + Description: mysql.Quote(alias, "description"), + Enabled: mysql.Quote(alias, "enabled"), + APIKey: mysql.Quote(alias, "api_key"), + APIUsername: mysql.Quote(alias, "api_username"), + RemoteName: mysql.Quote(alias, "remote_name"), + } +} + +type locationsPipelineColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UUID mysql.Expression + Description mysql.Expression + Enabled mysql.Expression + APIKey mysql.Expression + APIUsername mysql.Expression + RemoteName mysql.Expression +} + +func (c locationsPipelineColumns) Alias() string { + return c.tableAlias +} + +func (locationsPipelineColumns) AliasedAs(alias string) locationsPipelineColumns { + return buildLocationsPipelineColumns(alias) +} + +// LocationsPipelineSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsPipelineSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UUID omit.Val[string] `db:"uuid" ` + Description omitnull.Val[string] `db:"description" ` + Enabled omit.Val[bool] `db:"enabled" ` + APIKey omitnull.Val[string] `db:"api_key" ` + APIUsername omitnull.Val[string] `db:"api_username" ` + RemoteName omitnull.Val[string] `db:"remote_name" ` +} + +func (s LocationsPipelineSetter) SetColumns() []string { + vals := make([]string, 0, 7) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UUID.IsValue() { + vals = append(vals, "uuid") + } + if !s.Description.IsUnset() { + vals = append(vals, "description") + } + if s.Enabled.IsValue() { + vals = append(vals, "enabled") + } + if !s.APIKey.IsUnset() { + vals = append(vals, "api_key") + } + if !s.APIUsername.IsUnset() { + vals = append(vals, "api_username") + } + if !s.RemoteName.IsUnset() { + vals = append(vals, "remote_name") + } + return vals +} + +func (s LocationsPipelineSetter) Overwrite(t *LocationsPipeline) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UUID.IsValue() { + t.UUID = s.UUID.MustGet() + } + if !s.Description.IsUnset() { + t.Description = s.Description.MustGetNull() + } + if s.Enabled.IsValue() { + t.Enabled = s.Enabled.MustGet() + } + if !s.APIKey.IsUnset() { + t.APIKey = s.APIKey.MustGetNull() + } + if !s.APIUsername.IsUnset() { + t.APIUsername = s.APIUsername.MustGetNull() + } + if !s.RemoteName.IsUnset() { + t.RemoteName = s.RemoteName.MustGetNull() + } +} + +func (s *LocationsPipelineSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPipelines.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UUID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UUID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Description.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Description.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Enabled.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Enabled.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.APIKey.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.APIKey.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.APIUsername.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.APIUsername.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.RemoteName.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RemoteName.MustGetNull()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsPipelineSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_pipeline")...) +} + +func (s LocationsPipelineSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 7) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UUID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uuid")...), + mysql.Arg(s.UUID), + }}) + } + + if !s.Description.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "description")...), + mysql.Arg(s.Description), + }}) + } + + if s.Enabled.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "enabled")...), + mysql.Arg(s.Enabled), + }}) + } + + if !s.APIKey.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "api_key")...), + mysql.Arg(s.APIKey), + }}) + } + + if !s.APIUsername.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "api_username")...), + mysql.Arg(s.APIUsername), + }}) + } + + if !s.RemoteName.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "remote_name")...), + mysql.Arg(s.RemoteName), + }}) + } + + return exprs +} + +// FindLocationsPipeline retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsPipeline(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsPipeline, error) { + if len(cols) == 0 { + return LocationsPipelines.Query( + sm.Where(LocationsPipelines.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsPipelines.Query( + sm.Where(LocationsPipelines.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsPipelines.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsPipelineExists checks the presence of a single record by primary key +func LocationsPipelineExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsPipelines.Query( + sm.Where(LocationsPipelines.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsPipeline is retrieved from the database +func (o *LocationsPipeline) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPipelines.AfterSelectHooks.RunHooks(ctx, exec, LocationsPipelineSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsPipelines.AfterInsertHooks.RunHooks(ctx, exec, LocationsPipelineSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsPipelines.AfterUpdateHooks.RunHooks(ctx, exec, LocationsPipelineSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsPipelines.AfterDeleteHooks.RunHooks(ctx, exec, LocationsPipelineSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsPipeline +func (o *LocationsPipeline) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsPipeline) pkEQ() dialect.Expression { + return mysql.Quote("locations_pipeline", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsPipeline +func (o *LocationsPipeline) Update(ctx context.Context, exec bob.Executor, s *LocationsPipelineSetter) error { + _, err := LocationsPipelines.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsPipeline record with an executor +func (o *LocationsPipeline) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsPipelines.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsPipeline using the executor +func (o *LocationsPipeline) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsPipelines.Query( + sm.Where(LocationsPipelines.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsPipelineSlice is retrieved from the database +func (o LocationsPipelineSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPipelines.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsPipelines.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsPipelines.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsPipelines.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsPipelineSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_pipeline", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsPipelineSlice) copyMatchingRows(from ...*LocationsPipeline) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsPipelineSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPipelines.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPipeline: + o.copyMatchingRows(retrieved) + case []*LocationsPipeline: + o.copyMatchingRows(retrieved...) + case LocationsPipelineSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPipeline or a slice of LocationsPipeline + // then run the AfterUpdateHooks on the slice + _, err = LocationsPipelines.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsPipelineSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPipelines.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPipeline: + o.copyMatchingRows(retrieved) + case []*LocationsPipeline: + o.copyMatchingRows(retrieved...) + case LocationsPipelineSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPipeline or a slice of LocationsPipeline + // then run the AfterDeleteHooks on the slice + _, err = LocationsPipelines.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsPipelineSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsPipelineSetter) error { + _, err := LocationsPipelines.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsPipelineSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsPipelines.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsPipelineSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsPipelines.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// PipelineLocationsEvents starts a query for related objects on locations_event +func (o *LocationsPipeline) PipelineLocationsEvents(mods ...bob.Mod[*dialect.SelectQuery]) LocationsEventsQuery { + return LocationsEvents.Query(append(mods, + sm.Where(LocationsEvents.Columns.PipelineID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsPipelineSlice) PipelineLocationsEvents(mods ...bob.Mod[*dialect.SelectQuery]) LocationsEventsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsEvents.Query(append(mods, + sm.Where(mysql.Group(LocationsEvents.Columns.PipelineID).OP("IN", PKArgExpr)), + )...) +} + +// PipelineLocationsLocationpipelines starts a query for related objects on locations_locationpipeline +func (o *LocationsPipeline) PipelineLocationsLocationpipelines(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationpipelinesQuery { + return LocationsLocationpipelines.Query(append(mods, + sm.Where(LocationsLocationpipelines.Columns.PipelineID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsPipelineSlice) PipelineLocationsLocationpipelines(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationpipelinesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocationpipelines.Query(append(mods, + sm.Where(mysql.Group(LocationsLocationpipelines.Columns.PipelineID).OP("IN", PKArgExpr)), + )...) +} + +// OriginPipelineLocationsPackages starts a query for related objects on locations_package +func (o *LocationsPipeline) OriginPipelineLocationsPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.OriginPipelineID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsPipelineSlice) OriginPipelineLocationsPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.OriginPipelineID).OP("IN", PKArgExpr)), + )...) +} + +func insertLocationsPipelinePipelineLocationsEvents0(ctx context.Context, exec bob.Executor, locationsEvents1 []*LocationsEventSetter, locationsPipeline0 *LocationsPipeline) (LocationsEventSlice, error) { + for i := range locationsEvents1 { + locationsEvents1[i].PipelineID = omit.From(locationsPipeline0.UUID) + } + + ret, err := LocationsEvents.Insert(bob.ToMods(locationsEvents1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPipelinePipelineLocationsEvents0: %w", err) + } + + return ret, nil +} + +func attachLocationsPipelinePipelineLocationsEvents0(ctx context.Context, exec bob.Executor, count int, locationsEvents1 LocationsEventSlice, locationsPipeline0 *LocationsPipeline) (LocationsEventSlice, error) { + setter := &LocationsEventSetter{ + PipelineID: omit.From(locationsPipeline0.UUID), + } + + err := locationsEvents1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPipelinePipelineLocationsEvents0: %w", err) + } + + return locationsEvents1, nil +} + +func (locationsPipeline0 *LocationsPipeline) InsertPipelineLocationsEvents(ctx context.Context, exec bob.Executor, related ...*LocationsEventSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsEvents1, err := insertLocationsPipelinePipelineLocationsEvents0(ctx, exec, related, locationsPipeline0) + if err != nil { + return err + } + + locationsPipeline0.R.PipelineLocationsEvents = append(locationsPipeline0.R.PipelineLocationsEvents, locationsEvents1...) + + for _, rel := range locationsEvents1 { + rel.R.PipelineLocationsPipeline = locationsPipeline0 + } + return nil +} + +func (locationsPipeline0 *LocationsPipeline) AttachPipelineLocationsEvents(ctx context.Context, exec bob.Executor, related ...*LocationsEvent) error { + if len(related) == 0 { + return nil + } + + var err error + locationsEvents1 := LocationsEventSlice(related) + + _, err = attachLocationsPipelinePipelineLocationsEvents0(ctx, exec, len(related), locationsEvents1, locationsPipeline0) + if err != nil { + return err + } + + locationsPipeline0.R.PipelineLocationsEvents = append(locationsPipeline0.R.PipelineLocationsEvents, locationsEvents1...) + + for _, rel := range related { + rel.R.PipelineLocationsPipeline = locationsPipeline0 + } + + return nil +} + +func insertLocationsPipelinePipelineLocationsLocationpipelines0(ctx context.Context, exec bob.Executor, locationsLocationpipelines1 []*LocationsLocationpipelineSetter, locationsPipeline0 *LocationsPipeline) (LocationsLocationpipelineSlice, error) { + for i := range locationsLocationpipelines1 { + locationsLocationpipelines1[i].PipelineID = omit.From(locationsPipeline0.UUID) + } + + ret, err := LocationsLocationpipelines.Insert(bob.ToMods(locationsLocationpipelines1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPipelinePipelineLocationsLocationpipelines0: %w", err) + } + + return ret, nil +} + +func attachLocationsPipelinePipelineLocationsLocationpipelines0(ctx context.Context, exec bob.Executor, count int, locationsLocationpipelines1 LocationsLocationpipelineSlice, locationsPipeline0 *LocationsPipeline) (LocationsLocationpipelineSlice, error) { + setter := &LocationsLocationpipelineSetter{ + PipelineID: omit.From(locationsPipeline0.UUID), + } + + err := locationsLocationpipelines1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPipelinePipelineLocationsLocationpipelines0: %w", err) + } + + return locationsLocationpipelines1, nil +} + +func (locationsPipeline0 *LocationsPipeline) InsertPipelineLocationsLocationpipelines(ctx context.Context, exec bob.Executor, related ...*LocationsLocationpipelineSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsLocationpipelines1, err := insertLocationsPipelinePipelineLocationsLocationpipelines0(ctx, exec, related, locationsPipeline0) + if err != nil { + return err + } + + locationsPipeline0.R.PipelineLocationsLocationpipelines = append(locationsPipeline0.R.PipelineLocationsLocationpipelines, locationsLocationpipelines1...) + + for _, rel := range locationsLocationpipelines1 { + rel.R.PipelineLocationsPipeline = locationsPipeline0 + } + return nil +} + +func (locationsPipeline0 *LocationsPipeline) AttachPipelineLocationsLocationpipelines(ctx context.Context, exec bob.Executor, related ...*LocationsLocationpipeline) error { + if len(related) == 0 { + return nil + } + + var err error + locationsLocationpipelines1 := LocationsLocationpipelineSlice(related) + + _, err = attachLocationsPipelinePipelineLocationsLocationpipelines0(ctx, exec, len(related), locationsLocationpipelines1, locationsPipeline0) + if err != nil { + return err + } + + locationsPipeline0.R.PipelineLocationsLocationpipelines = append(locationsPipeline0.R.PipelineLocationsLocationpipelines, locationsLocationpipelines1...) + + for _, rel := range related { + rel.R.PipelineLocationsPipeline = locationsPipeline0 + } + + return nil +} + +func insertLocationsPipelineOriginPipelineLocationsPackages0(ctx context.Context, exec bob.Executor, locationsPackages1 []*LocationsPackageSetter, locationsPipeline0 *LocationsPipeline) (LocationsPackageSlice, error) { + for i := range locationsPackages1 { + locationsPackages1[i].OriginPipelineID = omitnull.From(locationsPipeline0.UUID) + } + + ret, err := LocationsPackages.Insert(bob.ToMods(locationsPackages1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPipelineOriginPipelineLocationsPackages0: %w", err) + } + + return ret, nil +} + +func attachLocationsPipelineOriginPipelineLocationsPackages0(ctx context.Context, exec bob.Executor, count int, locationsPackages1 LocationsPackageSlice, locationsPipeline0 *LocationsPipeline) (LocationsPackageSlice, error) { + setter := &LocationsPackageSetter{ + OriginPipelineID: omitnull.From(locationsPipeline0.UUID), + } + + err := locationsPackages1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPipelineOriginPipelineLocationsPackages0: %w", err) + } + + return locationsPackages1, nil +} + +func (locationsPipeline0 *LocationsPipeline) InsertOriginPipelineLocationsPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackageSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsPackages1, err := insertLocationsPipelineOriginPipelineLocationsPackages0(ctx, exec, related, locationsPipeline0) + if err != nil { + return err + } + + locationsPipeline0.R.OriginPipelineLocationsPackages = append(locationsPipeline0.R.OriginPipelineLocationsPackages, locationsPackages1...) + + for _, rel := range locationsPackages1 { + rel.R.OriginPipelineLocationsPipeline = locationsPipeline0 + } + return nil +} + +func (locationsPipeline0 *LocationsPipeline) AttachOriginPipelineLocationsPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackage) error { + if len(related) == 0 { + return nil + } + + var err error + locationsPackages1 := LocationsPackageSlice(related) + + _, err = attachLocationsPipelineOriginPipelineLocationsPackages0(ctx, exec, len(related), locationsPackages1, locationsPipeline0) + if err != nil { + return err + } + + locationsPipeline0.R.OriginPipelineLocationsPackages = append(locationsPipeline0.R.OriginPipelineLocationsPackages, locationsPackages1...) + + for _, rel := range related { + rel.R.OriginPipelineLocationsPipeline = locationsPipeline0 + } + + return nil +} + +type locationsPipelineWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UUID mysql.WhereMod[Q, string] + Description mysql.WhereNullMod[Q, string] + Enabled mysql.WhereMod[Q, bool] + APIKey mysql.WhereNullMod[Q, string] + APIUsername mysql.WhereNullMod[Q, string] + RemoteName mysql.WhereNullMod[Q, string] +} + +func (locationsPipelineWhere[Q]) AliasedAs(alias string) locationsPipelineWhere[Q] { + return buildLocationsPipelineWhere[Q](buildLocationsPipelineColumns(alias)) +} + +func buildLocationsPipelineWhere[Q mysql.Filterable](cols locationsPipelineColumns) locationsPipelineWhere[Q] { + return locationsPipelineWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UUID: mysql.Where[Q, string](cols.UUID), + Description: mysql.WhereNull[Q, string](cols.Description), + Enabled: mysql.Where[Q, bool](cols.Enabled), + APIKey: mysql.WhereNull[Q, string](cols.APIKey), + APIUsername: mysql.WhereNull[Q, string](cols.APIUsername), + RemoteName: mysql.WhereNull[Q, string](cols.RemoteName), + } +} + +func (o *LocationsPipeline) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "PipelineLocationsEvents": + rels, ok := retrieved.(LocationsEventSlice) + if !ok { + return fmt.Errorf("locationsPipeline cannot load %T as %q", retrieved, name) + } + + o.R.PipelineLocationsEvents = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PipelineLocationsPipeline = o + } + } + return nil + case "PipelineLocationsLocationpipelines": + rels, ok := retrieved.(LocationsLocationpipelineSlice) + if !ok { + return fmt.Errorf("locationsPipeline cannot load %T as %q", retrieved, name) + } + + o.R.PipelineLocationsLocationpipelines = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PipelineLocationsPipeline = o + } + } + return nil + case "OriginPipelineLocationsPackages": + rels, ok := retrieved.(LocationsPackageSlice) + if !ok { + return fmt.Errorf("locationsPipeline cannot load %T as %q", retrieved, name) + } + + o.R.OriginPipelineLocationsPackages = rels + + for _, rel := range rels { + if rel != nil { + rel.R.OriginPipelineLocationsPipeline = o + } + } + return nil + default: + return fmt.Errorf("locationsPipeline has no relationship %q", name) + } +} + +type locationsPipelinePreloader struct{} + +func buildLocationsPipelinePreloader() locationsPipelinePreloader { + return locationsPipelinePreloader{} +} + +type locationsPipelineThenLoader[Q orm.Loadable] struct { + PipelineLocationsEvents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PipelineLocationsLocationpipelines func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + OriginPipelineLocationsPackages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsPipelineThenLoader[Q orm.Loadable]() locationsPipelineThenLoader[Q] { + type PipelineLocationsEventsLoadInterface interface { + LoadPipelineLocationsEvents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PipelineLocationsLocationpipelinesLoadInterface interface { + LoadPipelineLocationsLocationpipelines(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type OriginPipelineLocationsPackagesLoadInterface interface { + LoadOriginPipelineLocationsPackages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsPipelineThenLoader[Q]{ + PipelineLocationsEvents: thenLoadBuilder[Q]( + "PipelineLocationsEvents", + func(ctx context.Context, exec bob.Executor, retrieved PipelineLocationsEventsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPipelineLocationsEvents(ctx, exec, mods...) + }, + ), + PipelineLocationsLocationpipelines: thenLoadBuilder[Q]( + "PipelineLocationsLocationpipelines", + func(ctx context.Context, exec bob.Executor, retrieved PipelineLocationsLocationpipelinesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPipelineLocationsLocationpipelines(ctx, exec, mods...) + }, + ), + OriginPipelineLocationsPackages: thenLoadBuilder[Q]( + "OriginPipelineLocationsPackages", + func(ctx context.Context, exec bob.Executor, retrieved OriginPipelineLocationsPackagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadOriginPipelineLocationsPackages(ctx, exec, mods...) + }, + ), + } +} + +// LoadPipelineLocationsEvents loads the locationsPipeline's PipelineLocationsEvents into the .R struct +func (o *LocationsPipeline) LoadPipelineLocationsEvents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PipelineLocationsEvents = nil + + related, err := o.PipelineLocationsEvents(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PipelineLocationsPipeline = o + } + + o.R.PipelineLocationsEvents = related + return nil +} + +// LoadPipelineLocationsEvents loads the locationsPipeline's PipelineLocationsEvents into the .R struct +func (os LocationsPipelineSlice) LoadPipelineLocationsEvents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsEvents, err := os.PipelineLocationsEvents(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PipelineLocationsEvents = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsEvents { + + if !(o.UUID == rel.PipelineID) { + continue + } + + rel.R.PipelineLocationsPipeline = o + + o.R.PipelineLocationsEvents = append(o.R.PipelineLocationsEvents, rel) + } + } + + return nil +} + +// LoadPipelineLocationsLocationpipelines loads the locationsPipeline's PipelineLocationsLocationpipelines into the .R struct +func (o *LocationsPipeline) LoadPipelineLocationsLocationpipelines(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PipelineLocationsLocationpipelines = nil + + related, err := o.PipelineLocationsLocationpipelines(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PipelineLocationsPipeline = o + } + + o.R.PipelineLocationsLocationpipelines = related + return nil +} + +// LoadPipelineLocationsLocationpipelines loads the locationsPipeline's PipelineLocationsLocationpipelines into the .R struct +func (os LocationsPipelineSlice) LoadPipelineLocationsLocationpipelines(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocationpipelines, err := os.PipelineLocationsLocationpipelines(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PipelineLocationsLocationpipelines = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocationpipelines { + + if !(o.UUID == rel.PipelineID) { + continue + } + + rel.R.PipelineLocationsPipeline = o + + o.R.PipelineLocationsLocationpipelines = append(o.R.PipelineLocationsLocationpipelines, rel) + } + } + + return nil +} + +// LoadOriginPipelineLocationsPackages loads the locationsPipeline's OriginPipelineLocationsPackages into the .R struct +func (o *LocationsPipeline) LoadOriginPipelineLocationsPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.OriginPipelineLocationsPackages = nil + + related, err := o.OriginPipelineLocationsPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.OriginPipelineLocationsPipeline = o + } + + o.R.OriginPipelineLocationsPackages = related + return nil +} + +// LoadOriginPipelineLocationsPackages loads the locationsPipeline's OriginPipelineLocationsPackages into the .R struct +func (os LocationsPipelineSlice) LoadOriginPipelineLocationsPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.OriginPipelineLocationsPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.OriginPipelineLocationsPackages = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !rel.OriginPipelineID.IsValue() { + continue + } + if !(rel.OriginPipelineID.IsValue() && o.UUID == rel.OriginPipelineID.MustGet()) { + continue + } + + rel.R.OriginPipelineLocationsPipeline = o + + o.R.OriginPipelineLocationsPackages = append(o.R.OriginPipelineLocationsPackages, rel) + } + } + + return nil +} + +type locationsPipelineJoins[Q dialect.Joinable] struct { + typ string + PipelineLocationsEvents modAs[Q, locationsEventColumns] + PipelineLocationsLocationpipelines modAs[Q, locationsLocationpipelineColumns] + OriginPipelineLocationsPackages modAs[Q, locationsPackageColumns] +} + +func (j locationsPipelineJoins[Q]) aliasedAs(alias string) locationsPipelineJoins[Q] { + return buildLocationsPipelineJoins[Q](buildLocationsPipelineColumns(alias), j.typ) +} + +func buildLocationsPipelineJoins[Q dialect.Joinable](cols locationsPipelineColumns, typ string) locationsPipelineJoins[Q] { + return locationsPipelineJoins[Q]{ + typ: typ, + PipelineLocationsEvents: modAs[Q, locationsEventColumns]{ + c: LocationsEvents.Columns, + f: func(to locationsEventColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsEvents.Name().As(to.Alias())).On( + to.PipelineID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + PipelineLocationsLocationpipelines: modAs[Q, locationsLocationpipelineColumns]{ + c: LocationsLocationpipelines.Columns, + f: func(to locationsLocationpipelineColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocationpipelines.Name().As(to.Alias())).On( + to.PipelineID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + OriginPipelineLocationsPackages: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.OriginPipelineID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_pipelinelocalfs.bob.go b/database/mcp/models/locations_pipelinelocalfs.bob.go new file mode 100644 index 0000000..87de74f --- /dev/null +++ b/database/mcp/models/locations_pipelinelocalfs.bob.go @@ -0,0 +1,688 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsPipelinelocalf is an object representing the database table. +type LocationsPipelinelocalf struct { + ID int32 `db:"id,pk,autoincr" ` + RemoteUser string `db:"remote_user" ` + RemoteName string `db:"remote_name" ` + SpaceID string `db:"space_id" ` + AssumeRsyncDaemon bool `db:"assume_rsync_daemon" ` + RsyncPassword string `db:"rsync_password" ` + + R locationsPipelinelocalfR `db:"-" ` +} + +// LocationsPipelinelocalfSlice is an alias for a slice of pointers to LocationsPipelinelocalf. +// This should almost always be used instead of []*LocationsPipelinelocalf. +type LocationsPipelinelocalfSlice []*LocationsPipelinelocalf + +// LocationsPipelinelocalfs contains methods to work with the locations_pipelinelocalfs table +var LocationsPipelinelocalfs = mysql.NewTablex[*LocationsPipelinelocalf, LocationsPipelinelocalfSlice, *LocationsPipelinelocalfSetter]("locations_pipelinelocalfs", buildLocationsPipelinelocalfColumns("locations_pipelinelocalfs"), []string{"id"}, []string{"space_id"}) + +// LocationsPipelinelocalfsQuery is a query on the locations_pipelinelocalfs table +type LocationsPipelinelocalfsQuery = *mysql.ViewQuery[*LocationsPipelinelocalf, LocationsPipelinelocalfSlice] + +// locationsPipelinelocalfR is where relationships are stored. +type locationsPipelinelocalfR struct { + SpaceLocationsSpace *LocationsSpace // locations_pipelinelo_space_id_6f6ba9f6_fk_locations +} + +func buildLocationsPipelinelocalfColumns(alias string) locationsPipelinelocalfColumns { + return locationsPipelinelocalfColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "remote_user", "remote_name", "space_id", "assume_rsync_daemon", "rsync_password", + ).WithParent("locations_pipelinelocalfs"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + RemoteUser: mysql.Quote(alias, "remote_user"), + RemoteName: mysql.Quote(alias, "remote_name"), + SpaceID: mysql.Quote(alias, "space_id"), + AssumeRsyncDaemon: mysql.Quote(alias, "assume_rsync_daemon"), + RsyncPassword: mysql.Quote(alias, "rsync_password"), + } +} + +type locationsPipelinelocalfColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + RemoteUser mysql.Expression + RemoteName mysql.Expression + SpaceID mysql.Expression + AssumeRsyncDaemon mysql.Expression + RsyncPassword mysql.Expression +} + +func (c locationsPipelinelocalfColumns) Alias() string { + return c.tableAlias +} + +func (locationsPipelinelocalfColumns) AliasedAs(alias string) locationsPipelinelocalfColumns { + return buildLocationsPipelinelocalfColumns(alias) +} + +// LocationsPipelinelocalfSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsPipelinelocalfSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + RemoteUser omit.Val[string] `db:"remote_user" ` + RemoteName omit.Val[string] `db:"remote_name" ` + SpaceID omit.Val[string] `db:"space_id" ` + AssumeRsyncDaemon omit.Val[bool] `db:"assume_rsync_daemon" ` + RsyncPassword omit.Val[string] `db:"rsync_password" ` +} + +func (s LocationsPipelinelocalfSetter) SetColumns() []string { + vals := make([]string, 0, 6) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.RemoteUser.IsValue() { + vals = append(vals, "remote_user") + } + if s.RemoteName.IsValue() { + vals = append(vals, "remote_name") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + if s.AssumeRsyncDaemon.IsValue() { + vals = append(vals, "assume_rsync_daemon") + } + if s.RsyncPassword.IsValue() { + vals = append(vals, "rsync_password") + } + return vals +} + +func (s LocationsPipelinelocalfSetter) Overwrite(t *LocationsPipelinelocalf) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.RemoteUser.IsValue() { + t.RemoteUser = s.RemoteUser.MustGet() + } + if s.RemoteName.IsValue() { + t.RemoteName = s.RemoteName.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } + if s.AssumeRsyncDaemon.IsValue() { + t.AssumeRsyncDaemon = s.AssumeRsyncDaemon.MustGet() + } + if s.RsyncPassword.IsValue() { + t.RsyncPassword = s.RsyncPassword.MustGet() + } +} + +func (s *LocationsPipelinelocalfSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPipelinelocalfs.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.RemoteUser.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RemoteUser.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.RemoteName.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RemoteName.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AssumeRsyncDaemon.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AssumeRsyncDaemon.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.RsyncPassword.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RsyncPassword.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsPipelinelocalfSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_pipelinelocalfs")...) +} + +func (s LocationsPipelinelocalfSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 6) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.RemoteUser.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "remote_user")...), + mysql.Arg(s.RemoteUser), + }}) + } + + if s.RemoteName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "remote_name")...), + mysql.Arg(s.RemoteName), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + if s.AssumeRsyncDaemon.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "assume_rsync_daemon")...), + mysql.Arg(s.AssumeRsyncDaemon), + }}) + } + + if s.RsyncPassword.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "rsync_password")...), + mysql.Arg(s.RsyncPassword), + }}) + } + + return exprs +} + +// FindLocationsPipelinelocalf retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsPipelinelocalf(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsPipelinelocalf, error) { + if len(cols) == 0 { + return LocationsPipelinelocalfs.Query( + sm.Where(LocationsPipelinelocalfs.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsPipelinelocalfs.Query( + sm.Where(LocationsPipelinelocalfs.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsPipelinelocalfs.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsPipelinelocalfExists checks the presence of a single record by primary key +func LocationsPipelinelocalfExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsPipelinelocalfs.Query( + sm.Where(LocationsPipelinelocalfs.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsPipelinelocalf is retrieved from the database +func (o *LocationsPipelinelocalf) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPipelinelocalfs.AfterSelectHooks.RunHooks(ctx, exec, LocationsPipelinelocalfSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsPipelinelocalfs.AfterInsertHooks.RunHooks(ctx, exec, LocationsPipelinelocalfSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsPipelinelocalfs.AfterUpdateHooks.RunHooks(ctx, exec, LocationsPipelinelocalfSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsPipelinelocalfs.AfterDeleteHooks.RunHooks(ctx, exec, LocationsPipelinelocalfSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsPipelinelocalf +func (o *LocationsPipelinelocalf) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsPipelinelocalf) pkEQ() dialect.Expression { + return mysql.Quote("locations_pipelinelocalfs", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsPipelinelocalf +func (o *LocationsPipelinelocalf) Update(ctx context.Context, exec bob.Executor, s *LocationsPipelinelocalfSetter) error { + _, err := LocationsPipelinelocalfs.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsPipelinelocalf record with an executor +func (o *LocationsPipelinelocalf) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsPipelinelocalfs.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsPipelinelocalf using the executor +func (o *LocationsPipelinelocalf) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsPipelinelocalfs.Query( + sm.Where(LocationsPipelinelocalfs.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsPipelinelocalfSlice is retrieved from the database +func (o LocationsPipelinelocalfSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPipelinelocalfs.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsPipelinelocalfs.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsPipelinelocalfs.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsPipelinelocalfs.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsPipelinelocalfSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_pipelinelocalfs", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsPipelinelocalfSlice) copyMatchingRows(from ...*LocationsPipelinelocalf) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsPipelinelocalfSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPipelinelocalfs.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPipelinelocalf: + o.copyMatchingRows(retrieved) + case []*LocationsPipelinelocalf: + o.copyMatchingRows(retrieved...) + case LocationsPipelinelocalfSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPipelinelocalf or a slice of LocationsPipelinelocalf + // then run the AfterUpdateHooks on the slice + _, err = LocationsPipelinelocalfs.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsPipelinelocalfSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPipelinelocalfs.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPipelinelocalf: + o.copyMatchingRows(retrieved) + case []*LocationsPipelinelocalf: + o.copyMatchingRows(retrieved...) + case LocationsPipelinelocalfSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPipelinelocalf or a slice of LocationsPipelinelocalf + // then run the AfterDeleteHooks on the slice + _, err = LocationsPipelinelocalfs.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsPipelinelocalfSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsPipelinelocalfSetter) error { + _, err := LocationsPipelinelocalfs.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsPipelinelocalfSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsPipelinelocalfs.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsPipelinelocalfSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsPipelinelocalfs.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsPipelinelocalf) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsPipelinelocalfSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsPipelinelocalfSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsPipelinelocalf0 *LocationsPipelinelocalf, locationsSpace1 *LocationsSpace) (*LocationsPipelinelocalf, error) { + setter := &LocationsPipelinelocalfSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsPipelinelocalf0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPipelinelocalfSpaceLocationsSpace0: %w", err) + } + + return locationsPipelinelocalf0, nil +} + +func (locationsPipelinelocalf0 *LocationsPipelinelocalf) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPipelinelocalfSpaceLocationsSpace0(ctx, exec, 1, locationsPipelinelocalf0, locationsSpace1) + if err != nil { + return err + } + + locationsPipelinelocalf0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsPipelinelocalf = locationsPipelinelocalf0 + + return nil +} + +func (locationsPipelinelocalf0 *LocationsPipelinelocalf) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsPipelinelocalfSpaceLocationsSpace0(ctx, exec, 1, locationsPipelinelocalf0, locationsSpace1) + if err != nil { + return err + } + + locationsPipelinelocalf0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsPipelinelocalf = locationsPipelinelocalf0 + + return nil +} + +type locationsPipelinelocalfWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + RemoteUser mysql.WhereMod[Q, string] + RemoteName mysql.WhereMod[Q, string] + SpaceID mysql.WhereMod[Q, string] + AssumeRsyncDaemon mysql.WhereMod[Q, bool] + RsyncPassword mysql.WhereMod[Q, string] +} + +func (locationsPipelinelocalfWhere[Q]) AliasedAs(alias string) locationsPipelinelocalfWhere[Q] { + return buildLocationsPipelinelocalfWhere[Q](buildLocationsPipelinelocalfColumns(alias)) +} + +func buildLocationsPipelinelocalfWhere[Q mysql.Filterable](cols locationsPipelinelocalfColumns) locationsPipelinelocalfWhere[Q] { + return locationsPipelinelocalfWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + RemoteUser: mysql.Where[Q, string](cols.RemoteUser), + RemoteName: mysql.Where[Q, string](cols.RemoteName), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + AssumeRsyncDaemon: mysql.Where[Q, bool](cols.AssumeRsyncDaemon), + RsyncPassword: mysql.Where[Q, string](cols.RsyncPassword), + } +} + +func (o *LocationsPipelinelocalf) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsPipelinelocalf cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsPipelinelocalf = o + } + return nil + default: + return fmt.Errorf("locationsPipelinelocalf has no relationship %q", name) + } +} + +type locationsPipelinelocalfPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsPipelinelocalfPreloader() locationsPipelinelocalfPreloader { + return locationsPipelinelocalfPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsPipelinelocalfs, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsPipelinelocalfThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsPipelinelocalfThenLoader[Q orm.Loadable]() locationsPipelinelocalfThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsPipelinelocalfThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsPipelinelocalf's SpaceLocationsSpace into the .R struct +func (o *LocationsPipelinelocalf) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsPipelinelocalf = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsPipelinelocalf's SpaceLocationsSpace into the .R struct +func (os LocationsPipelinelocalfSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsPipelinelocalf = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsPipelinelocalfJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsPipelinelocalfJoins[Q]) aliasedAs(alias string) locationsPipelinelocalfJoins[Q] { + return buildLocationsPipelinelocalfJoins[Q](buildLocationsPipelinelocalfColumns(alias), j.typ) +} + +func buildLocationsPipelinelocalfJoins[Q dialect.Joinable](cols locationsPipelinelocalfColumns, typ string) locationsPipelinelocalfJoins[Q] { + return locationsPipelinelocalfJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_rclone.bob.go b/database/mcp/models/locations_rclone.bob.go new file mode 100644 index 0000000..0cb3137 --- /dev/null +++ b/database/mcp/models/locations_rclone.bob.go @@ -0,0 +1,640 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsRclone is an object representing the database table. +type LocationsRclone struct { + ID int32 `db:"id,pk,autoincr" ` + RemoteName string `db:"remote_name" ` + Container string `db:"container" ` + SpaceID string `db:"space_id" ` + + R locationsRcloneR `db:"-" ` +} + +// LocationsRcloneSlice is an alias for a slice of pointers to LocationsRclone. +// This should almost always be used instead of []*LocationsRclone. +type LocationsRcloneSlice []*LocationsRclone + +// LocationsRclones contains methods to work with the locations_rclone table +var LocationsRclones = mysql.NewTablex[*LocationsRclone, LocationsRcloneSlice, *LocationsRcloneSetter]("locations_rclone", buildLocationsRcloneColumns("locations_rclone"), []string{"id"}, []string{"space_id"}) + +// LocationsRclonesQuery is a query on the locations_rclone table +type LocationsRclonesQuery = *mysql.ViewQuery[*LocationsRclone, LocationsRcloneSlice] + +// locationsRcloneR is where relationships are stored. +type locationsRcloneR struct { + SpaceLocationsSpace *LocationsSpace // locations_rclone_space_id_adb7fd1d_fk_locations_space_uuid +} + +func buildLocationsRcloneColumns(alias string) locationsRcloneColumns { + return locationsRcloneColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "remote_name", "container", "space_id", + ).WithParent("locations_rclone"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + RemoteName: mysql.Quote(alias, "remote_name"), + Container: mysql.Quote(alias, "container"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsRcloneColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + RemoteName mysql.Expression + Container mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsRcloneColumns) Alias() string { + return c.tableAlias +} + +func (locationsRcloneColumns) AliasedAs(alias string) locationsRcloneColumns { + return buildLocationsRcloneColumns(alias) +} + +// LocationsRcloneSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsRcloneSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + RemoteName omit.Val[string] `db:"remote_name" ` + Container omit.Val[string] `db:"container" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsRcloneSetter) SetColumns() []string { + vals := make([]string, 0, 4) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.RemoteName.IsValue() { + vals = append(vals, "remote_name") + } + if s.Container.IsValue() { + vals = append(vals, "container") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsRcloneSetter) Overwrite(t *LocationsRclone) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.RemoteName.IsValue() { + t.RemoteName = s.RemoteName.MustGet() + } + if s.Container.IsValue() { + t.Container = s.Container.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsRcloneSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsRclones.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.RemoteName.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RemoteName.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Container.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Container.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsRcloneSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_rclone")...) +} + +func (s LocationsRcloneSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 4) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.RemoteName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "remote_name")...), + mysql.Arg(s.RemoteName), + }}) + } + + if s.Container.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "container")...), + mysql.Arg(s.Container), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsRclone retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsRclone(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsRclone, error) { + if len(cols) == 0 { + return LocationsRclones.Query( + sm.Where(LocationsRclones.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsRclones.Query( + sm.Where(LocationsRclones.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsRclones.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsRcloneExists checks the presence of a single record by primary key +func LocationsRcloneExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsRclones.Query( + sm.Where(LocationsRclones.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsRclone is retrieved from the database +func (o *LocationsRclone) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsRclones.AfterSelectHooks.RunHooks(ctx, exec, LocationsRcloneSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsRclones.AfterInsertHooks.RunHooks(ctx, exec, LocationsRcloneSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsRclones.AfterUpdateHooks.RunHooks(ctx, exec, LocationsRcloneSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsRclones.AfterDeleteHooks.RunHooks(ctx, exec, LocationsRcloneSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsRclone +func (o *LocationsRclone) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsRclone) pkEQ() dialect.Expression { + return mysql.Quote("locations_rclone", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsRclone +func (o *LocationsRclone) Update(ctx context.Context, exec bob.Executor, s *LocationsRcloneSetter) error { + _, err := LocationsRclones.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsRclone record with an executor +func (o *LocationsRclone) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsRclones.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsRclone using the executor +func (o *LocationsRclone) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsRclones.Query( + sm.Where(LocationsRclones.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsRcloneSlice is retrieved from the database +func (o LocationsRcloneSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsRclones.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsRclones.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsRclones.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsRclones.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsRcloneSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_rclone", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsRcloneSlice) copyMatchingRows(from ...*LocationsRclone) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsRcloneSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsRclones.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsRclone: + o.copyMatchingRows(retrieved) + case []*LocationsRclone: + o.copyMatchingRows(retrieved...) + case LocationsRcloneSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsRclone or a slice of LocationsRclone + // then run the AfterUpdateHooks on the slice + _, err = LocationsRclones.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsRcloneSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsRclones.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsRclone: + o.copyMatchingRows(retrieved) + case []*LocationsRclone: + o.copyMatchingRows(retrieved...) + case LocationsRcloneSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsRclone or a slice of LocationsRclone + // then run the AfterDeleteHooks on the slice + _, err = LocationsRclones.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsRcloneSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsRcloneSetter) error { + _, err := LocationsRclones.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsRcloneSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsRclones.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsRcloneSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsRclones.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsRclone) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsRcloneSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsRcloneSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsRclone0 *LocationsRclone, locationsSpace1 *LocationsSpace) (*LocationsRclone, error) { + setter := &LocationsRcloneSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsRclone0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsRcloneSpaceLocationsSpace0: %w", err) + } + + return locationsRclone0, nil +} + +func (locationsRclone0 *LocationsRclone) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsRcloneSpaceLocationsSpace0(ctx, exec, 1, locationsRclone0, locationsSpace1) + if err != nil { + return err + } + + locationsRclone0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsRclone = locationsRclone0 + + return nil +} + +func (locationsRclone0 *LocationsRclone) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsRcloneSpaceLocationsSpace0(ctx, exec, 1, locationsRclone0, locationsSpace1) + if err != nil { + return err + } + + locationsRclone0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsRclone = locationsRclone0 + + return nil +} + +type locationsRcloneWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + RemoteName mysql.WhereMod[Q, string] + Container mysql.WhereMod[Q, string] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsRcloneWhere[Q]) AliasedAs(alias string) locationsRcloneWhere[Q] { + return buildLocationsRcloneWhere[Q](buildLocationsRcloneColumns(alias)) +} + +func buildLocationsRcloneWhere[Q mysql.Filterable](cols locationsRcloneColumns) locationsRcloneWhere[Q] { + return locationsRcloneWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + RemoteName: mysql.Where[Q, string](cols.RemoteName), + Container: mysql.Where[Q, string](cols.Container), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsRclone) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsRclone cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsRclone = o + } + return nil + default: + return fmt.Errorf("locationsRclone has no relationship %q", name) + } +} + +type locationsRclonePreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsRclonePreloader() locationsRclonePreloader { + return locationsRclonePreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsRclones, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsRcloneThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsRcloneThenLoader[Q orm.Loadable]() locationsRcloneThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsRcloneThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsRclone's SpaceLocationsSpace into the .R struct +func (o *LocationsRclone) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsRclone = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsRclone's SpaceLocationsSpace into the .R struct +func (os LocationsRcloneSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsRclone = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsRcloneJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsRcloneJoins[Q]) aliasedAs(alias string) locationsRcloneJoins[Q] { + return buildLocationsRcloneJoins[Q](buildLocationsRcloneColumns(alias), j.typ) +} + +func buildLocationsRcloneJoins[Q dialect.Joinable](cols locationsRcloneColumns, typ string) locationsRcloneJoins[Q] { + return locationsRcloneJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_s3.bob.go b/database/mcp/models/locations_s3.bob.go new file mode 100644 index 0000000..db21d99 --- /dev/null +++ b/database/mcp/models/locations_s3.bob.go @@ -0,0 +1,712 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsS3 is an object representing the database table. +type LocationsS3 struct { + ID int32 `db:"id,pk,autoincr" ` + EndpointURL string `db:"endpoint_url" ` + AccessKeyID string `db:"access_key_id" ` + SecretAccessKey string `db:"secret_access_key" ` + Region string `db:"region" ` + SpaceID string `db:"space_id" ` + Bucket string `db:"bucket" ` + + R locationsS3R `db:"-" ` +} + +// LocationsS3Slice is an alias for a slice of pointers to LocationsS3. +// This should almost always be used instead of []*LocationsS3. +type LocationsS3Slice []*LocationsS3 + +// LocationsS3S contains methods to work with the locations_s3 table +var LocationsS3S = mysql.NewTablex[*LocationsS3, LocationsS3Slice, *LocationsS3Setter]("locations_s3", buildLocationsS3Columns("locations_s3"), []string{"id"}, []string{"space_id"}) + +// LocationsS3SQuery is a query on the locations_s3 table +type LocationsS3SQuery = *mysql.ViewQuery[*LocationsS3, LocationsS3Slice] + +// locationsS3R is where relationships are stored. +type locationsS3R struct { + SpaceLocationsSpace *LocationsSpace // locations_s3_space_id_d8fc3ba3_fk_locations_space_uuid +} + +func buildLocationsS3Columns(alias string) locationsS3Columns { + return locationsS3Columns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "endpoint_url", "access_key_id", "secret_access_key", "region", "space_id", "bucket", + ).WithParent("locations_s3"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + EndpointURL: mysql.Quote(alias, "endpoint_url"), + AccessKeyID: mysql.Quote(alias, "access_key_id"), + SecretAccessKey: mysql.Quote(alias, "secret_access_key"), + Region: mysql.Quote(alias, "region"), + SpaceID: mysql.Quote(alias, "space_id"), + Bucket: mysql.Quote(alias, "bucket"), + } +} + +type locationsS3Columns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + EndpointURL mysql.Expression + AccessKeyID mysql.Expression + SecretAccessKey mysql.Expression + Region mysql.Expression + SpaceID mysql.Expression + Bucket mysql.Expression +} + +func (c locationsS3Columns) Alias() string { + return c.tableAlias +} + +func (locationsS3Columns) AliasedAs(alias string) locationsS3Columns { + return buildLocationsS3Columns(alias) +} + +// LocationsS3Setter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsS3Setter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + EndpointURL omit.Val[string] `db:"endpoint_url" ` + AccessKeyID omit.Val[string] `db:"access_key_id" ` + SecretAccessKey omit.Val[string] `db:"secret_access_key" ` + Region omit.Val[string] `db:"region" ` + SpaceID omit.Val[string] `db:"space_id" ` + Bucket omit.Val[string] `db:"bucket" ` +} + +func (s LocationsS3Setter) SetColumns() []string { + vals := make([]string, 0, 7) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.EndpointURL.IsValue() { + vals = append(vals, "endpoint_url") + } + if s.AccessKeyID.IsValue() { + vals = append(vals, "access_key_id") + } + if s.SecretAccessKey.IsValue() { + vals = append(vals, "secret_access_key") + } + if s.Region.IsValue() { + vals = append(vals, "region") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + if s.Bucket.IsValue() { + vals = append(vals, "bucket") + } + return vals +} + +func (s LocationsS3Setter) Overwrite(t *LocationsS3) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.EndpointURL.IsValue() { + t.EndpointURL = s.EndpointURL.MustGet() + } + if s.AccessKeyID.IsValue() { + t.AccessKeyID = s.AccessKeyID.MustGet() + } + if s.SecretAccessKey.IsValue() { + t.SecretAccessKey = s.SecretAccessKey.MustGet() + } + if s.Region.IsValue() { + t.Region = s.Region.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } + if s.Bucket.IsValue() { + t.Bucket = s.Bucket.MustGet() + } +} + +func (s *LocationsS3Setter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsS3S.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.EndpointURL.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.EndpointURL.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AccessKeyID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AccessKeyID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SecretAccessKey.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SecretAccessKey.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Region.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Region.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Bucket.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Bucket.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsS3Setter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_s3")...) +} + +func (s LocationsS3Setter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 7) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.EndpointURL.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "endpoint_url")...), + mysql.Arg(s.EndpointURL), + }}) + } + + if s.AccessKeyID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "access_key_id")...), + mysql.Arg(s.AccessKeyID), + }}) + } + + if s.SecretAccessKey.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "secret_access_key")...), + mysql.Arg(s.SecretAccessKey), + }}) + } + + if s.Region.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "region")...), + mysql.Arg(s.Region), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + if s.Bucket.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "bucket")...), + mysql.Arg(s.Bucket), + }}) + } + + return exprs +} + +// FindLocationsS3 retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsS3(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsS3, error) { + if len(cols) == 0 { + return LocationsS3S.Query( + sm.Where(LocationsS3S.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsS3S.Query( + sm.Where(LocationsS3S.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsS3S.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsS3Exists checks the presence of a single record by primary key +func LocationsS3Exists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsS3S.Query( + sm.Where(LocationsS3S.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsS3 is retrieved from the database +func (o *LocationsS3) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsS3S.AfterSelectHooks.RunHooks(ctx, exec, LocationsS3Slice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsS3S.AfterInsertHooks.RunHooks(ctx, exec, LocationsS3Slice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsS3S.AfterUpdateHooks.RunHooks(ctx, exec, LocationsS3Slice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsS3S.AfterDeleteHooks.RunHooks(ctx, exec, LocationsS3Slice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsS3 +func (o *LocationsS3) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsS3) pkEQ() dialect.Expression { + return mysql.Quote("locations_s3", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsS3 +func (o *LocationsS3) Update(ctx context.Context, exec bob.Executor, s *LocationsS3Setter) error { + _, err := LocationsS3S.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsS3 record with an executor +func (o *LocationsS3) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsS3S.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsS3 using the executor +func (o *LocationsS3) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsS3S.Query( + sm.Where(LocationsS3S.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsS3Slice is retrieved from the database +func (o LocationsS3Slice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsS3S.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsS3S.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsS3S.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsS3S.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsS3Slice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_s3", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsS3Slice) copyMatchingRows(from ...*LocationsS3) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsS3Slice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsS3S.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsS3: + o.copyMatchingRows(retrieved) + case []*LocationsS3: + o.copyMatchingRows(retrieved...) + case LocationsS3Slice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsS3 or a slice of LocationsS3 + // then run the AfterUpdateHooks on the slice + _, err = LocationsS3S.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsS3Slice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsS3S.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsS3: + o.copyMatchingRows(retrieved) + case []*LocationsS3: + o.copyMatchingRows(retrieved...) + case LocationsS3Slice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsS3 or a slice of LocationsS3 + // then run the AfterDeleteHooks on the slice + _, err = LocationsS3S.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsS3Slice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsS3Setter) error { + _, err := LocationsS3S.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsS3Slice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsS3S.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsS3Slice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsS3S.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsS3) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsS3Slice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsS3SpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsS30 *LocationsS3, locationsSpace1 *LocationsSpace) (*LocationsS3, error) { + setter := &LocationsS3Setter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsS30.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsS3SpaceLocationsSpace0: %w", err) + } + + return locationsS30, nil +} + +func (locationsS30 *LocationsS3) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsS3SpaceLocationsSpace0(ctx, exec, 1, locationsS30, locationsSpace1) + if err != nil { + return err + } + + locationsS30.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsS3 = locationsS30 + + return nil +} + +func (locationsS30 *LocationsS3) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsS3SpaceLocationsSpace0(ctx, exec, 1, locationsS30, locationsSpace1) + if err != nil { + return err + } + + locationsS30.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsS3 = locationsS30 + + return nil +} + +type locationsS3Where[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + EndpointURL mysql.WhereMod[Q, string] + AccessKeyID mysql.WhereMod[Q, string] + SecretAccessKey mysql.WhereMod[Q, string] + Region mysql.WhereMod[Q, string] + SpaceID mysql.WhereMod[Q, string] + Bucket mysql.WhereMod[Q, string] +} + +func (locationsS3Where[Q]) AliasedAs(alias string) locationsS3Where[Q] { + return buildLocationsS3Where[Q](buildLocationsS3Columns(alias)) +} + +func buildLocationsS3Where[Q mysql.Filterable](cols locationsS3Columns) locationsS3Where[Q] { + return locationsS3Where[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + EndpointURL: mysql.Where[Q, string](cols.EndpointURL), + AccessKeyID: mysql.Where[Q, string](cols.AccessKeyID), + SecretAccessKey: mysql.Where[Q, string](cols.SecretAccessKey), + Region: mysql.Where[Q, string](cols.Region), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + Bucket: mysql.Where[Q, string](cols.Bucket), + } +} + +func (o *LocationsS3) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsS3 cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsS3 = o + } + return nil + default: + return fmt.Errorf("locationsS3 has no relationship %q", name) + } +} + +type locationsS3Preloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsS3Preloader() locationsS3Preloader { + return locationsS3Preloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsS3S, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsS3ThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsS3ThenLoader[Q orm.Loadable]() locationsS3ThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsS3ThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsS3's SpaceLocationsSpace into the .R struct +func (o *LocationsS3) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsS3 = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsS3's SpaceLocationsSpace into the .R struct +func (os LocationsS3Slice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsS3 = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsS3Joins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsS3Joins[Q]) aliasedAs(alias string) locationsS3Joins[Q] { + return buildLocationsS3Joins[Q](buildLocationsS3Columns(alias), j.typ) +} + +func buildLocationsS3Joins[Q dialect.Joinable](cols locationsS3Columns, typ string) locationsS3Joins[Q] { + return locationsS3Joins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_space.bob.go b/database/mcp/models/locations_space.bob.go new file mode 100644 index 0000000..da5716d --- /dev/null +++ b/database/mcp/models/locations_space.bob.go @@ -0,0 +1,3612 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsSpace is an object representing the database table. +type LocationsSpace struct { + ID int32 `db:"id,pk,autoincr" ` + UUID string `db:"uuid" ` + AccessProtocol string `db:"access_protocol" ` + Size null.Val[int64] `db:"size" ` + Used int64 `db:"used" ` + Path string `db:"path" ` + Verified bool `db:"verified" ` + LastVerified null.Val[time.Time] `db:"last_verified" ` + StagingPath string `db:"staging_path" ` + + R locationsSpaceR `db:"-" ` +} + +// LocationsSpaceSlice is an alias for a slice of pointers to LocationsSpace. +// This should almost always be used instead of []*LocationsSpace. +type LocationsSpaceSlice []*LocationsSpace + +// LocationsSpaces contains methods to work with the locations_space table +var LocationsSpaces = mysql.NewTablex[*LocationsSpace, LocationsSpaceSlice, *LocationsSpaceSetter]("locations_space", buildLocationsSpaceColumns("locations_space"), []string{"id"}, []string{"uuid"}) + +// LocationsSpacesQuery is a query on the locations_space table +type LocationsSpacesQuery = *mysql.ViewQuery[*LocationsSpace, LocationsSpaceSlice] + +// locationsSpaceR is where relationships are stored. +type locationsSpaceR struct { + SpaceLocationsArchipelago *LocationsArchipelago // locations_archipelago_space_id_be47fd5c_fk_locations_space_uuid + SpaceLocationsArkivum *LocationsArkivum // locations_arkivum_space_id_d159e309_fk_locations_space_uuid + SpaceLocationsDataverse *LocationsDataverse // locations_dataverse_space_id_1b94d732_fk_locations_space_uuid + SpaceLocationsDspace *LocationsDspace // locations_dspace_space_id_e1c12ce1_fk_locations_space_uuid + SpaceLocationsDspacerest *LocationsDspacerest // locations_dspacerest_space_id_6ae6a82b_fk_locations_space_uuid + SpaceLocationsDuracloud *LocationsDuracloud // locations_duracloud_space_id_753df0f2_fk_locations_space_uuid + SpaceLocationsFedora *LocationsFedora // locations_fedora_space_id_088fe895_fk_locations_space_uuid + SpaceLocationsGPG *LocationsGPG // locations_gpg_space_id_6223440d_fk_locations_space_uuid + SpaceLocationsLocalfilesystem *LocationsLocalfilesystem // locations_localfiles_space_id_a97d3d9f_fk_locations + SpaceLocationsLocations LocationsLocationSlice // locations_location_space_id_748845a7_fk_locations_space_uuid + SpaceLocationsLockssomatic *LocationsLockssomatic // locations_lockssomatic_space_id_cc6a3cd6_fk_locations_space_uuid + SpaceLocationsNF *LocationsNF // locations_nfs_space_id_34913c3b_fk_locations_space_uuid + SpaceLocationsOfflinereplicastaging *LocationsOfflinereplicastaging // locations_offlinerep_space_id_2a8d7578_fk_locations + SpaceLocationsPipelinelocalf *LocationsPipelinelocalf // locations_pipelinelo_space_id_6f6ba9f6_fk_locations + SpaceLocationsRclone *LocationsRclone // locations_rclone_space_id_adb7fd1d_fk_locations_space_uuid + SpaceLocationsS3 *LocationsS3 // locations_s3_space_id_d8fc3ba3_fk_locations_space_uuid + SpaceLocationsSwift *LocationsSwift // locations_swift_space_id_9cfded49_fk_locations_space_uuid +} + +func buildLocationsSpaceColumns(alias string) locationsSpaceColumns { + return locationsSpaceColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "uuid", "access_protocol", "size", "used", "path", "verified", "last_verified", "staging_path", + ).WithParent("locations_space"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UUID: mysql.Quote(alias, "uuid"), + AccessProtocol: mysql.Quote(alias, "access_protocol"), + Size: mysql.Quote(alias, "size"), + Used: mysql.Quote(alias, "used"), + Path: mysql.Quote(alias, "path"), + Verified: mysql.Quote(alias, "verified"), + LastVerified: mysql.Quote(alias, "last_verified"), + StagingPath: mysql.Quote(alias, "staging_path"), + } +} + +type locationsSpaceColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UUID mysql.Expression + AccessProtocol mysql.Expression + Size mysql.Expression + Used mysql.Expression + Path mysql.Expression + Verified mysql.Expression + LastVerified mysql.Expression + StagingPath mysql.Expression +} + +func (c locationsSpaceColumns) Alias() string { + return c.tableAlias +} + +func (locationsSpaceColumns) AliasedAs(alias string) locationsSpaceColumns { + return buildLocationsSpaceColumns(alias) +} + +// LocationsSpaceSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsSpaceSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UUID omit.Val[string] `db:"uuid" ` + AccessProtocol omit.Val[string] `db:"access_protocol" ` + Size omitnull.Val[int64] `db:"size" ` + Used omit.Val[int64] `db:"used" ` + Path omit.Val[string] `db:"path" ` + Verified omit.Val[bool] `db:"verified" ` + LastVerified omitnull.Val[time.Time] `db:"last_verified" ` + StagingPath omit.Val[string] `db:"staging_path" ` +} + +func (s LocationsSpaceSetter) SetColumns() []string { + vals := make([]string, 0, 9) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UUID.IsValue() { + vals = append(vals, "uuid") + } + if s.AccessProtocol.IsValue() { + vals = append(vals, "access_protocol") + } + if !s.Size.IsUnset() { + vals = append(vals, "size") + } + if s.Used.IsValue() { + vals = append(vals, "used") + } + if s.Path.IsValue() { + vals = append(vals, "path") + } + if s.Verified.IsValue() { + vals = append(vals, "verified") + } + if !s.LastVerified.IsUnset() { + vals = append(vals, "last_verified") + } + if s.StagingPath.IsValue() { + vals = append(vals, "staging_path") + } + return vals +} + +func (s LocationsSpaceSetter) Overwrite(t *LocationsSpace) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UUID.IsValue() { + t.UUID = s.UUID.MustGet() + } + if s.AccessProtocol.IsValue() { + t.AccessProtocol = s.AccessProtocol.MustGet() + } + if !s.Size.IsUnset() { + t.Size = s.Size.MustGetNull() + } + if s.Used.IsValue() { + t.Used = s.Used.MustGet() + } + if s.Path.IsValue() { + t.Path = s.Path.MustGet() + } + if s.Verified.IsValue() { + t.Verified = s.Verified.MustGet() + } + if !s.LastVerified.IsUnset() { + t.LastVerified = s.LastVerified.MustGetNull() + } + if s.StagingPath.IsValue() { + t.StagingPath = s.StagingPath.MustGet() + } +} + +func (s *LocationsSpaceSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsSpaces.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UUID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UUID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AccessProtocol.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AccessProtocol.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Size.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Size.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Used.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Used.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Path.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Path.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Verified.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Verified.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.LastVerified.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.LastVerified.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.StagingPath.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.StagingPath.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsSpaceSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_space")...) +} + +func (s LocationsSpaceSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 9) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UUID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uuid")...), + mysql.Arg(s.UUID), + }}) + } + + if s.AccessProtocol.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "access_protocol")...), + mysql.Arg(s.AccessProtocol), + }}) + } + + if !s.Size.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "size")...), + mysql.Arg(s.Size), + }}) + } + + if s.Used.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "used")...), + mysql.Arg(s.Used), + }}) + } + + if s.Path.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "path")...), + mysql.Arg(s.Path), + }}) + } + + if s.Verified.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "verified")...), + mysql.Arg(s.Verified), + }}) + } + + if !s.LastVerified.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "last_verified")...), + mysql.Arg(s.LastVerified), + }}) + } + + if s.StagingPath.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "staging_path")...), + mysql.Arg(s.StagingPath), + }}) + } + + return exprs +} + +// FindLocationsSpace retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsSpace(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsSpace, error) { + if len(cols) == 0 { + return LocationsSpaces.Query( + sm.Where(LocationsSpaces.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsSpaces.Query( + sm.Where(LocationsSpaces.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsSpaces.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsSpaceExists checks the presence of a single record by primary key +func LocationsSpaceExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsSpaces.Query( + sm.Where(LocationsSpaces.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsSpace is retrieved from the database +func (o *LocationsSpace) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsSpaces.AfterSelectHooks.RunHooks(ctx, exec, LocationsSpaceSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsSpaces.AfterInsertHooks.RunHooks(ctx, exec, LocationsSpaceSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsSpaces.AfterUpdateHooks.RunHooks(ctx, exec, LocationsSpaceSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsSpaces.AfterDeleteHooks.RunHooks(ctx, exec, LocationsSpaceSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsSpace +func (o *LocationsSpace) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsSpace) pkEQ() dialect.Expression { + return mysql.Quote("locations_space", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsSpace +func (o *LocationsSpace) Update(ctx context.Context, exec bob.Executor, s *LocationsSpaceSetter) error { + _, err := LocationsSpaces.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsSpace record with an executor +func (o *LocationsSpace) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsSpaces.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsSpace using the executor +func (o *LocationsSpace) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsSpaces.Query( + sm.Where(LocationsSpaces.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsSpaceSlice is retrieved from the database +func (o LocationsSpaceSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsSpaces.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsSpaces.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsSpaces.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsSpaces.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsSpaceSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_space", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsSpaceSlice) copyMatchingRows(from ...*LocationsSpace) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsSpaceSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsSpaces.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsSpace: + o.copyMatchingRows(retrieved) + case []*LocationsSpace: + o.copyMatchingRows(retrieved...) + case LocationsSpaceSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsSpace or a slice of LocationsSpace + // then run the AfterUpdateHooks on the slice + _, err = LocationsSpaces.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsSpaceSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsSpaces.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsSpace: + o.copyMatchingRows(retrieved) + case []*LocationsSpace: + o.copyMatchingRows(retrieved...) + case LocationsSpaceSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsSpace or a slice of LocationsSpace + // then run the AfterDeleteHooks on the slice + _, err = LocationsSpaces.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsSpaceSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsSpaceSetter) error { + _, err := LocationsSpaces.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsSpaceSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsSpaces.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsSpaceSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsSpaces.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsArchipelago starts a query for related objects on locations_archipelago +func (o *LocationsSpace) SpaceLocationsArchipelago(mods ...bob.Mod[*dialect.SelectQuery]) LocationsArchipelagosQuery { + return LocationsArchipelagos.Query(append(mods, + sm.Where(LocationsArchipelagos.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsArchipelago(mods ...bob.Mod[*dialect.SelectQuery]) LocationsArchipelagosQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsArchipelagos.Query(append(mods, + sm.Where(mysql.Group(LocationsArchipelagos.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsArkivum starts a query for related objects on locations_arkivum +func (o *LocationsSpace) SpaceLocationsArkivum(mods ...bob.Mod[*dialect.SelectQuery]) LocationsArkivumsQuery { + return LocationsArkivums.Query(append(mods, + sm.Where(LocationsArkivums.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsArkivum(mods ...bob.Mod[*dialect.SelectQuery]) LocationsArkivumsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsArkivums.Query(append(mods, + sm.Where(mysql.Group(LocationsArkivums.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsDataverse starts a query for related objects on locations_dataverse +func (o *LocationsSpace) SpaceLocationsDataverse(mods ...bob.Mod[*dialect.SelectQuery]) LocationsDataversesQuery { + return LocationsDataverses.Query(append(mods, + sm.Where(LocationsDataverses.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsDataverse(mods ...bob.Mod[*dialect.SelectQuery]) LocationsDataversesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsDataverses.Query(append(mods, + sm.Where(mysql.Group(LocationsDataverses.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsDspace starts a query for related objects on locations_dspace +func (o *LocationsSpace) SpaceLocationsDspace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsDspacesQuery { + return LocationsDspaces.Query(append(mods, + sm.Where(LocationsDspaces.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsDspace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsDspacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsDspaces.Query(append(mods, + sm.Where(mysql.Group(LocationsDspaces.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsDspacerest starts a query for related objects on locations_dspacerest +func (o *LocationsSpace) SpaceLocationsDspacerest(mods ...bob.Mod[*dialect.SelectQuery]) LocationsDspacerestsQuery { + return LocationsDspacerests.Query(append(mods, + sm.Where(LocationsDspacerests.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsDspacerest(mods ...bob.Mod[*dialect.SelectQuery]) LocationsDspacerestsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsDspacerests.Query(append(mods, + sm.Where(mysql.Group(LocationsDspacerests.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsDuracloud starts a query for related objects on locations_duracloud +func (o *LocationsSpace) SpaceLocationsDuracloud(mods ...bob.Mod[*dialect.SelectQuery]) LocationsDuracloudsQuery { + return LocationsDuraclouds.Query(append(mods, + sm.Where(LocationsDuraclouds.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsDuracloud(mods ...bob.Mod[*dialect.SelectQuery]) LocationsDuracloudsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsDuraclouds.Query(append(mods, + sm.Where(mysql.Group(LocationsDuraclouds.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsFedora starts a query for related objects on locations_fedora +func (o *LocationsSpace) SpaceLocationsFedora(mods ...bob.Mod[*dialect.SelectQuery]) LocationsFedorasQuery { + return LocationsFedoras.Query(append(mods, + sm.Where(LocationsFedoras.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsFedora(mods ...bob.Mod[*dialect.SelectQuery]) LocationsFedorasQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsFedoras.Query(append(mods, + sm.Where(mysql.Group(LocationsFedoras.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsGPG starts a query for related objects on locations_gpg +func (o *LocationsSpace) SpaceLocationsGPG(mods ...bob.Mod[*dialect.SelectQuery]) LocationsGPGSQuery { + return LocationsGPGS.Query(append(mods, + sm.Where(LocationsGPGS.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsGPG(mods ...bob.Mod[*dialect.SelectQuery]) LocationsGPGSQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsGPGS.Query(append(mods, + sm.Where(mysql.Group(LocationsGPGS.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsLocalfilesystem starts a query for related objects on locations_localfilesystem +func (o *LocationsSpace) SpaceLocationsLocalfilesystem(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocalfilesystemsQuery { + return LocationsLocalfilesystems.Query(append(mods, + sm.Where(LocationsLocalfilesystems.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsLocalfilesystem(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocalfilesystemsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocalfilesystems.Query(append(mods, + sm.Where(mysql.Group(LocationsLocalfilesystems.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsLocations starts a query for related objects on locations_location +func (o *LocationsSpace) SpaceLocationsLocations(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + return LocationsLocations.Query(append(mods, + sm.Where(LocationsLocations.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsLocations(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocations.Query(append(mods, + sm.Where(mysql.Group(LocationsLocations.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsLockssomatic starts a query for related objects on locations_lockssomatic +func (o *LocationsSpace) SpaceLocationsLockssomatic(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLockssomaticsQuery { + return LocationsLockssomatics.Query(append(mods, + sm.Where(LocationsLockssomatics.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsLockssomatic(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLockssomaticsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLockssomatics.Query(append(mods, + sm.Where(mysql.Group(LocationsLockssomatics.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsNF starts a query for related objects on locations_nfs +func (o *LocationsSpace) SpaceLocationsNF(mods ...bob.Mod[*dialect.SelectQuery]) LocationsNFSQuery { + return LocationsNFS.Query(append(mods, + sm.Where(LocationsNFS.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsNF(mods ...bob.Mod[*dialect.SelectQuery]) LocationsNFSQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsNFS.Query(append(mods, + sm.Where(mysql.Group(LocationsNFS.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsOfflinereplicastaging starts a query for related objects on locations_offlinereplicastaging +func (o *LocationsSpace) SpaceLocationsOfflinereplicastaging(mods ...bob.Mod[*dialect.SelectQuery]) LocationsOfflinereplicastagingsQuery { + return LocationsOfflinereplicastagings.Query(append(mods, + sm.Where(LocationsOfflinereplicastagings.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsOfflinereplicastaging(mods ...bob.Mod[*dialect.SelectQuery]) LocationsOfflinereplicastagingsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsOfflinereplicastagings.Query(append(mods, + sm.Where(mysql.Group(LocationsOfflinereplicastagings.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsPipelinelocalf starts a query for related objects on locations_pipelinelocalfs +func (o *LocationsSpace) SpaceLocationsPipelinelocalf(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPipelinelocalfsQuery { + return LocationsPipelinelocalfs.Query(append(mods, + sm.Where(LocationsPipelinelocalfs.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsPipelinelocalf(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPipelinelocalfsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPipelinelocalfs.Query(append(mods, + sm.Where(mysql.Group(LocationsPipelinelocalfs.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsRclone starts a query for related objects on locations_rclone +func (o *LocationsSpace) SpaceLocationsRclone(mods ...bob.Mod[*dialect.SelectQuery]) LocationsRclonesQuery { + return LocationsRclones.Query(append(mods, + sm.Where(LocationsRclones.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsRclone(mods ...bob.Mod[*dialect.SelectQuery]) LocationsRclonesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsRclones.Query(append(mods, + sm.Where(mysql.Group(LocationsRclones.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsS3 starts a query for related objects on locations_s3 +func (o *LocationsSpace) SpaceLocationsS3(mods ...bob.Mod[*dialect.SelectQuery]) LocationsS3SQuery { + return LocationsS3S.Query(append(mods, + sm.Where(LocationsS3S.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsS3(mods ...bob.Mod[*dialect.SelectQuery]) LocationsS3SQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsS3S.Query(append(mods, + sm.Where(mysql.Group(LocationsS3S.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsSwift starts a query for related objects on locations_swift +func (o *LocationsSpace) SpaceLocationsSwift(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSwiftsQuery { + return LocationsSwifts.Query(append(mods, + sm.Where(LocationsSwifts.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsSwift(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSwiftsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSwifts.Query(append(mods, + sm.Where(mysql.Group(LocationsSwifts.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +func insertLocationsSpaceSpaceLocationsArchipelago0(ctx context.Context, exec bob.Executor, locationsArchipelago1 *LocationsArchipelagoSetter, locationsSpace0 *LocationsSpace) (*LocationsArchipelago, error) { + locationsArchipelago1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsArchipelagos.Insert(locationsArchipelago1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsArchipelago0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsArchipelago0(ctx context.Context, exec bob.Executor, count int, locationsArchipelago1 *LocationsArchipelago, locationsSpace0 *LocationsSpace) (*LocationsArchipelago, error) { + setter := &LocationsArchipelagoSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsArchipelago1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsArchipelago0: %w", err) + } + + return locationsArchipelago1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsArchipelago(ctx context.Context, exec bob.Executor, related *LocationsArchipelagoSetter) error { + var err error + + locationsArchipelago1, err := insertLocationsSpaceSpaceLocationsArchipelago0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsArchipelago = locationsArchipelago1 + + locationsArchipelago1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsArchipelago(ctx context.Context, exec bob.Executor, locationsArchipelago1 *LocationsArchipelago) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsArchipelago0(ctx, exec, 1, locationsArchipelago1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsArchipelago = locationsArchipelago1 + + locationsArchipelago1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsArkivum0(ctx context.Context, exec bob.Executor, locationsArkivum1 *LocationsArkivumSetter, locationsSpace0 *LocationsSpace) (*LocationsArkivum, error) { + locationsArkivum1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsArkivums.Insert(locationsArkivum1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsArkivum0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsArkivum0(ctx context.Context, exec bob.Executor, count int, locationsArkivum1 *LocationsArkivum, locationsSpace0 *LocationsSpace) (*LocationsArkivum, error) { + setter := &LocationsArkivumSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsArkivum1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsArkivum0: %w", err) + } + + return locationsArkivum1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsArkivum(ctx context.Context, exec bob.Executor, related *LocationsArkivumSetter) error { + var err error + + locationsArkivum1, err := insertLocationsSpaceSpaceLocationsArkivum0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsArkivum = locationsArkivum1 + + locationsArkivum1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsArkivum(ctx context.Context, exec bob.Executor, locationsArkivum1 *LocationsArkivum) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsArkivum0(ctx, exec, 1, locationsArkivum1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsArkivum = locationsArkivum1 + + locationsArkivum1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsDataverse0(ctx context.Context, exec bob.Executor, locationsDataverse1 *LocationsDataverseSetter, locationsSpace0 *LocationsSpace) (*LocationsDataverse, error) { + locationsDataverse1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsDataverses.Insert(locationsDataverse1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsDataverse0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsDataverse0(ctx context.Context, exec bob.Executor, count int, locationsDataverse1 *LocationsDataverse, locationsSpace0 *LocationsSpace) (*LocationsDataverse, error) { + setter := &LocationsDataverseSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsDataverse1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsDataverse0: %w", err) + } + + return locationsDataverse1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsDataverse(ctx context.Context, exec bob.Executor, related *LocationsDataverseSetter) error { + var err error + + locationsDataverse1, err := insertLocationsSpaceSpaceLocationsDataverse0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsDataverse = locationsDataverse1 + + locationsDataverse1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsDataverse(ctx context.Context, exec bob.Executor, locationsDataverse1 *LocationsDataverse) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsDataverse0(ctx, exec, 1, locationsDataverse1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsDataverse = locationsDataverse1 + + locationsDataverse1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsDspace0(ctx context.Context, exec bob.Executor, locationsDspace1 *LocationsDspaceSetter, locationsSpace0 *LocationsSpace) (*LocationsDspace, error) { + locationsDspace1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsDspaces.Insert(locationsDspace1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsDspace0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsDspace0(ctx context.Context, exec bob.Executor, count int, locationsDspace1 *LocationsDspace, locationsSpace0 *LocationsSpace) (*LocationsDspace, error) { + setter := &LocationsDspaceSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsDspace1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsDspace0: %w", err) + } + + return locationsDspace1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsDspace(ctx context.Context, exec bob.Executor, related *LocationsDspaceSetter) error { + var err error + + locationsDspace1, err := insertLocationsSpaceSpaceLocationsDspace0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsDspace = locationsDspace1 + + locationsDspace1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsDspace(ctx context.Context, exec bob.Executor, locationsDspace1 *LocationsDspace) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsDspace0(ctx, exec, 1, locationsDspace1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsDspace = locationsDspace1 + + locationsDspace1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsDspacerest0(ctx context.Context, exec bob.Executor, locationsDspacerest1 *LocationsDspacerestSetter, locationsSpace0 *LocationsSpace) (*LocationsDspacerest, error) { + locationsDspacerest1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsDspacerests.Insert(locationsDspacerest1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsDspacerest0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsDspacerest0(ctx context.Context, exec bob.Executor, count int, locationsDspacerest1 *LocationsDspacerest, locationsSpace0 *LocationsSpace) (*LocationsDspacerest, error) { + setter := &LocationsDspacerestSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsDspacerest1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsDspacerest0: %w", err) + } + + return locationsDspacerest1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsDspacerest(ctx context.Context, exec bob.Executor, related *LocationsDspacerestSetter) error { + var err error + + locationsDspacerest1, err := insertLocationsSpaceSpaceLocationsDspacerest0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsDspacerest = locationsDspacerest1 + + locationsDspacerest1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsDspacerest(ctx context.Context, exec bob.Executor, locationsDspacerest1 *LocationsDspacerest) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsDspacerest0(ctx, exec, 1, locationsDspacerest1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsDspacerest = locationsDspacerest1 + + locationsDspacerest1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsDuracloud0(ctx context.Context, exec bob.Executor, locationsDuracloud1 *LocationsDuracloudSetter, locationsSpace0 *LocationsSpace) (*LocationsDuracloud, error) { + locationsDuracloud1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsDuraclouds.Insert(locationsDuracloud1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsDuracloud0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsDuracloud0(ctx context.Context, exec bob.Executor, count int, locationsDuracloud1 *LocationsDuracloud, locationsSpace0 *LocationsSpace) (*LocationsDuracloud, error) { + setter := &LocationsDuracloudSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsDuracloud1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsDuracloud0: %w", err) + } + + return locationsDuracloud1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsDuracloud(ctx context.Context, exec bob.Executor, related *LocationsDuracloudSetter) error { + var err error + + locationsDuracloud1, err := insertLocationsSpaceSpaceLocationsDuracloud0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsDuracloud = locationsDuracloud1 + + locationsDuracloud1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsDuracloud(ctx context.Context, exec bob.Executor, locationsDuracloud1 *LocationsDuracloud) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsDuracloud0(ctx, exec, 1, locationsDuracloud1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsDuracloud = locationsDuracloud1 + + locationsDuracloud1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsFedora0(ctx context.Context, exec bob.Executor, locationsFedora1 *LocationsFedoraSetter, locationsSpace0 *LocationsSpace) (*LocationsFedora, error) { + locationsFedora1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsFedoras.Insert(locationsFedora1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsFedora0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsFedora0(ctx context.Context, exec bob.Executor, count int, locationsFedora1 *LocationsFedora, locationsSpace0 *LocationsSpace) (*LocationsFedora, error) { + setter := &LocationsFedoraSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsFedora1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsFedora0: %w", err) + } + + return locationsFedora1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsFedora(ctx context.Context, exec bob.Executor, related *LocationsFedoraSetter) error { + var err error + + locationsFedora1, err := insertLocationsSpaceSpaceLocationsFedora0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsFedora = locationsFedora1 + + locationsFedora1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsFedora(ctx context.Context, exec bob.Executor, locationsFedora1 *LocationsFedora) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsFedora0(ctx, exec, 1, locationsFedora1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsFedora = locationsFedora1 + + locationsFedora1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsGPG0(ctx context.Context, exec bob.Executor, locationsGPG1 *LocationsGPGSetter, locationsSpace0 *LocationsSpace) (*LocationsGPG, error) { + locationsGPG1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsGPGS.Insert(locationsGPG1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsGPG0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsGPG0(ctx context.Context, exec bob.Executor, count int, locationsGPG1 *LocationsGPG, locationsSpace0 *LocationsSpace) (*LocationsGPG, error) { + setter := &LocationsGPGSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsGPG1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsGPG0: %w", err) + } + + return locationsGPG1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsGPG(ctx context.Context, exec bob.Executor, related *LocationsGPGSetter) error { + var err error + + locationsGPG1, err := insertLocationsSpaceSpaceLocationsGPG0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsGPG = locationsGPG1 + + locationsGPG1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsGPG(ctx context.Context, exec bob.Executor, locationsGPG1 *LocationsGPG) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsGPG0(ctx, exec, 1, locationsGPG1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsGPG = locationsGPG1 + + locationsGPG1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsLocalfilesystem0(ctx context.Context, exec bob.Executor, locationsLocalfilesystem1 *LocationsLocalfilesystemSetter, locationsSpace0 *LocationsSpace) (*LocationsLocalfilesystem, error) { + locationsLocalfilesystem1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsLocalfilesystems.Insert(locationsLocalfilesystem1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsLocalfilesystem0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsLocalfilesystem0(ctx context.Context, exec bob.Executor, count int, locationsLocalfilesystem1 *LocationsLocalfilesystem, locationsSpace0 *LocationsSpace) (*LocationsLocalfilesystem, error) { + setter := &LocationsLocalfilesystemSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsLocalfilesystem1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsLocalfilesystem0: %w", err) + } + + return locationsLocalfilesystem1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsLocalfilesystem(ctx context.Context, exec bob.Executor, related *LocationsLocalfilesystemSetter) error { + var err error + + locationsLocalfilesystem1, err := insertLocationsSpaceSpaceLocationsLocalfilesystem0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsLocalfilesystem = locationsLocalfilesystem1 + + locationsLocalfilesystem1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsLocalfilesystem(ctx context.Context, exec bob.Executor, locationsLocalfilesystem1 *LocationsLocalfilesystem) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsLocalfilesystem0(ctx, exec, 1, locationsLocalfilesystem1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsLocalfilesystem = locationsLocalfilesystem1 + + locationsLocalfilesystem1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsLocations0(ctx context.Context, exec bob.Executor, locationsLocations1 []*LocationsLocationSetter, locationsSpace0 *LocationsSpace) (LocationsLocationSlice, error) { + for i := range locationsLocations1 { + locationsLocations1[i].SpaceID = omit.From(locationsSpace0.UUID) + } + + ret, err := LocationsLocations.Insert(bob.ToMods(locationsLocations1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsLocations0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsLocations0(ctx context.Context, exec bob.Executor, count int, locationsLocations1 LocationsLocationSlice, locationsSpace0 *LocationsSpace) (LocationsLocationSlice, error) { + setter := &LocationsLocationSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsLocations1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsLocations0: %w", err) + } + + return locationsLocations1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsLocations(ctx context.Context, exec bob.Executor, related ...*LocationsLocationSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsLocations1, err := insertLocationsSpaceSpaceLocationsLocations0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsLocations = append(locationsSpace0.R.SpaceLocationsLocations, locationsLocations1...) + + for _, rel := range locationsLocations1 { + rel.R.SpaceLocationsSpace = locationsSpace0 + } + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsLocations(ctx context.Context, exec bob.Executor, related ...*LocationsLocation) error { + if len(related) == 0 { + return nil + } + + var err error + locationsLocations1 := LocationsLocationSlice(related) + + _, err = attachLocationsSpaceSpaceLocationsLocations0(ctx, exec, len(related), locationsLocations1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsLocations = append(locationsSpace0.R.SpaceLocationsLocations, locationsLocations1...) + + for _, rel := range related { + rel.R.SpaceLocationsSpace = locationsSpace0 + } + + return nil +} + +func insertLocationsSpaceSpaceLocationsLockssomatic0(ctx context.Context, exec bob.Executor, locationsLockssomatic1 *LocationsLockssomaticSetter, locationsSpace0 *LocationsSpace) (*LocationsLockssomatic, error) { + locationsLockssomatic1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsLockssomatics.Insert(locationsLockssomatic1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsLockssomatic0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsLockssomatic0(ctx context.Context, exec bob.Executor, count int, locationsLockssomatic1 *LocationsLockssomatic, locationsSpace0 *LocationsSpace) (*LocationsLockssomatic, error) { + setter := &LocationsLockssomaticSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsLockssomatic1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsLockssomatic0: %w", err) + } + + return locationsLockssomatic1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsLockssomatic(ctx context.Context, exec bob.Executor, related *LocationsLockssomaticSetter) error { + var err error + + locationsLockssomatic1, err := insertLocationsSpaceSpaceLocationsLockssomatic0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsLockssomatic = locationsLockssomatic1 + + locationsLockssomatic1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsLockssomatic(ctx context.Context, exec bob.Executor, locationsLockssomatic1 *LocationsLockssomatic) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsLockssomatic0(ctx, exec, 1, locationsLockssomatic1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsLockssomatic = locationsLockssomatic1 + + locationsLockssomatic1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsNF0(ctx context.Context, exec bob.Executor, locationsNF1 *LocationsNFSetter, locationsSpace0 *LocationsSpace) (*LocationsNF, error) { + locationsNF1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsNFS.Insert(locationsNF1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsNF0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsNF0(ctx context.Context, exec bob.Executor, count int, locationsNF1 *LocationsNF, locationsSpace0 *LocationsSpace) (*LocationsNF, error) { + setter := &LocationsNFSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsNF1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsNF0: %w", err) + } + + return locationsNF1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsNF(ctx context.Context, exec bob.Executor, related *LocationsNFSetter) error { + var err error + + locationsNF1, err := insertLocationsSpaceSpaceLocationsNF0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsNF = locationsNF1 + + locationsNF1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsNF(ctx context.Context, exec bob.Executor, locationsNF1 *LocationsNF) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsNF0(ctx, exec, 1, locationsNF1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsNF = locationsNF1 + + locationsNF1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsOfflinereplicastaging0(ctx context.Context, exec bob.Executor, locationsOfflinereplicastaging1 *LocationsOfflinereplicastagingSetter, locationsSpace0 *LocationsSpace) (*LocationsOfflinereplicastaging, error) { + locationsOfflinereplicastaging1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsOfflinereplicastagings.Insert(locationsOfflinereplicastaging1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsOfflinereplicastaging0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsOfflinereplicastaging0(ctx context.Context, exec bob.Executor, count int, locationsOfflinereplicastaging1 *LocationsOfflinereplicastaging, locationsSpace0 *LocationsSpace) (*LocationsOfflinereplicastaging, error) { + setter := &LocationsOfflinereplicastagingSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsOfflinereplicastaging1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsOfflinereplicastaging0: %w", err) + } + + return locationsOfflinereplicastaging1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsOfflinereplicastaging(ctx context.Context, exec bob.Executor, related *LocationsOfflinereplicastagingSetter) error { + var err error + + locationsOfflinereplicastaging1, err := insertLocationsSpaceSpaceLocationsOfflinereplicastaging0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsOfflinereplicastaging = locationsOfflinereplicastaging1 + + locationsOfflinereplicastaging1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsOfflinereplicastaging(ctx context.Context, exec bob.Executor, locationsOfflinereplicastaging1 *LocationsOfflinereplicastaging) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsOfflinereplicastaging0(ctx, exec, 1, locationsOfflinereplicastaging1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsOfflinereplicastaging = locationsOfflinereplicastaging1 + + locationsOfflinereplicastaging1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsPipelinelocalf0(ctx context.Context, exec bob.Executor, locationsPipelinelocalf1 *LocationsPipelinelocalfSetter, locationsSpace0 *LocationsSpace) (*LocationsPipelinelocalf, error) { + locationsPipelinelocalf1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsPipelinelocalfs.Insert(locationsPipelinelocalf1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsPipelinelocalf0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsPipelinelocalf0(ctx context.Context, exec bob.Executor, count int, locationsPipelinelocalf1 *LocationsPipelinelocalf, locationsSpace0 *LocationsSpace) (*LocationsPipelinelocalf, error) { + setter := &LocationsPipelinelocalfSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsPipelinelocalf1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsPipelinelocalf0: %w", err) + } + + return locationsPipelinelocalf1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsPipelinelocalf(ctx context.Context, exec bob.Executor, related *LocationsPipelinelocalfSetter) error { + var err error + + locationsPipelinelocalf1, err := insertLocationsSpaceSpaceLocationsPipelinelocalf0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsPipelinelocalf = locationsPipelinelocalf1 + + locationsPipelinelocalf1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsPipelinelocalf(ctx context.Context, exec bob.Executor, locationsPipelinelocalf1 *LocationsPipelinelocalf) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsPipelinelocalf0(ctx, exec, 1, locationsPipelinelocalf1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsPipelinelocalf = locationsPipelinelocalf1 + + locationsPipelinelocalf1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsRclone0(ctx context.Context, exec bob.Executor, locationsRclone1 *LocationsRcloneSetter, locationsSpace0 *LocationsSpace) (*LocationsRclone, error) { + locationsRclone1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsRclones.Insert(locationsRclone1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsRclone0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsRclone0(ctx context.Context, exec bob.Executor, count int, locationsRclone1 *LocationsRclone, locationsSpace0 *LocationsSpace) (*LocationsRclone, error) { + setter := &LocationsRcloneSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsRclone1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsRclone0: %w", err) + } + + return locationsRclone1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsRclone(ctx context.Context, exec bob.Executor, related *LocationsRcloneSetter) error { + var err error + + locationsRclone1, err := insertLocationsSpaceSpaceLocationsRclone0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsRclone = locationsRclone1 + + locationsRclone1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsRclone(ctx context.Context, exec bob.Executor, locationsRclone1 *LocationsRclone) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsRclone0(ctx, exec, 1, locationsRclone1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsRclone = locationsRclone1 + + locationsRclone1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsS30(ctx context.Context, exec bob.Executor, locationsS31 *LocationsS3Setter, locationsSpace0 *LocationsSpace) (*LocationsS3, error) { + locationsS31.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsS3S.Insert(locationsS31).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsS30: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsS30(ctx context.Context, exec bob.Executor, count int, locationsS31 *LocationsS3, locationsSpace0 *LocationsSpace) (*LocationsS3, error) { + setter := &LocationsS3Setter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsS31.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsS30: %w", err) + } + + return locationsS31, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsS3(ctx context.Context, exec bob.Executor, related *LocationsS3Setter) error { + var err error + + locationsS31, err := insertLocationsSpaceSpaceLocationsS30(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsS3 = locationsS31 + + locationsS31.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsS3(ctx context.Context, exec bob.Executor, locationsS31 *LocationsS3) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsS30(ctx, exec, 1, locationsS31, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsS3 = locationsS31 + + locationsS31.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsSwift0(ctx context.Context, exec bob.Executor, locationsSwift1 *LocationsSwiftSetter, locationsSpace0 *LocationsSpace) (*LocationsSwift, error) { + locationsSwift1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsSwifts.Insert(locationsSwift1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsSwift0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsSwift0(ctx context.Context, exec bob.Executor, count int, locationsSwift1 *LocationsSwift, locationsSpace0 *LocationsSpace) (*LocationsSwift, error) { + setter := &LocationsSwiftSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsSwift1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsSwift0: %w", err) + } + + return locationsSwift1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsSwift(ctx context.Context, exec bob.Executor, related *LocationsSwiftSetter) error { + var err error + + locationsSwift1, err := insertLocationsSpaceSpaceLocationsSwift0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsSwift = locationsSwift1 + + locationsSwift1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsSwift(ctx context.Context, exec bob.Executor, locationsSwift1 *LocationsSwift) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsSwift0(ctx, exec, 1, locationsSwift1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsSwift = locationsSwift1 + + locationsSwift1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +type locationsSpaceWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UUID mysql.WhereMod[Q, string] + AccessProtocol mysql.WhereMod[Q, string] + Size mysql.WhereNullMod[Q, int64] + Used mysql.WhereMod[Q, int64] + Path mysql.WhereMod[Q, string] + Verified mysql.WhereMod[Q, bool] + LastVerified mysql.WhereNullMod[Q, time.Time] + StagingPath mysql.WhereMod[Q, string] +} + +func (locationsSpaceWhere[Q]) AliasedAs(alias string) locationsSpaceWhere[Q] { + return buildLocationsSpaceWhere[Q](buildLocationsSpaceColumns(alias)) +} + +func buildLocationsSpaceWhere[Q mysql.Filterable](cols locationsSpaceColumns) locationsSpaceWhere[Q] { + return locationsSpaceWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UUID: mysql.Where[Q, string](cols.UUID), + AccessProtocol: mysql.Where[Q, string](cols.AccessProtocol), + Size: mysql.WhereNull[Q, int64](cols.Size), + Used: mysql.Where[Q, int64](cols.Used), + Path: mysql.Where[Q, string](cols.Path), + Verified: mysql.Where[Q, bool](cols.Verified), + LastVerified: mysql.WhereNull[Q, time.Time](cols.LastVerified), + StagingPath: mysql.Where[Q, string](cols.StagingPath), + } +} + +func (o *LocationsSpace) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsArchipelago": + rel, ok := retrieved.(*LocationsArchipelago) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsArchipelago = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsArkivum": + rel, ok := retrieved.(*LocationsArkivum) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsArkivum = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsDataverse": + rel, ok := retrieved.(*LocationsDataverse) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsDataverse = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsDspace": + rel, ok := retrieved.(*LocationsDspace) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsDspace = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsDspacerest": + rel, ok := retrieved.(*LocationsDspacerest) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsDspacerest = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsDuracloud": + rel, ok := retrieved.(*LocationsDuracloud) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsDuracloud = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsFedora": + rel, ok := retrieved.(*LocationsFedora) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsFedora = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsGPG": + rel, ok := retrieved.(*LocationsGPG) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsGPG = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsLocalfilesystem": + rel, ok := retrieved.(*LocationsLocalfilesystem) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsLocalfilesystem = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsLocations": + rels, ok := retrieved.(LocationsLocationSlice) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsLocations = rels + + for _, rel := range rels { + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + } + return nil + case "SpaceLocationsLockssomatic": + rel, ok := retrieved.(*LocationsLockssomatic) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsLockssomatic = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsNF": + rel, ok := retrieved.(*LocationsNF) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsNF = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsOfflinereplicastaging": + rel, ok := retrieved.(*LocationsOfflinereplicastaging) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsOfflinereplicastaging = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsPipelinelocalf": + rel, ok := retrieved.(*LocationsPipelinelocalf) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsPipelinelocalf = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsRclone": + rel, ok := retrieved.(*LocationsRclone) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsRclone = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsS3": + rel, ok := retrieved.(*LocationsS3) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsS3 = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsSwift": + rel, ok := retrieved.(*LocationsSwift) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSwift = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + default: + return fmt.Errorf("locationsSpace has no relationship %q", name) + } +} + +type locationsSpacePreloader struct { + SpaceLocationsArchipelago func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsArkivum func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsDataverse func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsDspace func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsDspacerest func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsDuracloud func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsFedora func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsGPG func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsLocalfilesystem func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsLockssomatic func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsNF func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsOfflinereplicastaging func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsPipelinelocalf func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsRclone func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsS3 func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsSwift func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsSpacePreloader() locationsSpacePreloader { + return locationsSpacePreloader{ + SpaceLocationsArchipelago: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsArchipelago, LocationsArchipelagoSlice](mysql.PreloadRel{ + Name: "SpaceLocationsArchipelago", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsArchipelagos, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsArchipelagos.Columns.Names(), opts...) + }, + SpaceLocationsArkivum: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsArkivum, LocationsArkivumSlice](mysql.PreloadRel{ + Name: "SpaceLocationsArkivum", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsArkivums, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsArkivums.Columns.Names(), opts...) + }, + SpaceLocationsDataverse: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsDataverse, LocationsDataverseSlice](mysql.PreloadRel{ + Name: "SpaceLocationsDataverse", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsDataverses, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsDataverses.Columns.Names(), opts...) + }, + SpaceLocationsDspace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsDspace, LocationsDspaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsDspace", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsDspaces, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsDspaces.Columns.Names(), opts...) + }, + SpaceLocationsDspacerest: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsDspacerest, LocationsDspacerestSlice](mysql.PreloadRel{ + Name: "SpaceLocationsDspacerest", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsDspacerests, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsDspacerests.Columns.Names(), opts...) + }, + SpaceLocationsDuracloud: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsDuracloud, LocationsDuracloudSlice](mysql.PreloadRel{ + Name: "SpaceLocationsDuracloud", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsDuraclouds, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsDuraclouds.Columns.Names(), opts...) + }, + SpaceLocationsFedora: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsFedora, LocationsFedoraSlice](mysql.PreloadRel{ + Name: "SpaceLocationsFedora", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsFedoras, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsFedoras.Columns.Names(), opts...) + }, + SpaceLocationsGPG: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsGPG, LocationsGPGSlice](mysql.PreloadRel{ + Name: "SpaceLocationsGPG", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsGPGS, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsGPGS.Columns.Names(), opts...) + }, + SpaceLocationsLocalfilesystem: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsLocalfilesystem, LocationsLocalfilesystemSlice](mysql.PreloadRel{ + Name: "SpaceLocationsLocalfilesystem", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsLocalfilesystems, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsLocalfilesystems.Columns.Names(), opts...) + }, + SpaceLocationsLockssomatic: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsLockssomatic, LocationsLockssomaticSlice](mysql.PreloadRel{ + Name: "SpaceLocationsLockssomatic", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsLockssomatics, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsLockssomatics.Columns.Names(), opts...) + }, + SpaceLocationsNF: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsNF, LocationsNFSlice](mysql.PreloadRel{ + Name: "SpaceLocationsNF", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsNFS, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsNFS.Columns.Names(), opts...) + }, + SpaceLocationsOfflinereplicastaging: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsOfflinereplicastaging, LocationsOfflinereplicastagingSlice](mysql.PreloadRel{ + Name: "SpaceLocationsOfflinereplicastaging", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsOfflinereplicastagings, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsOfflinereplicastagings.Columns.Names(), opts...) + }, + SpaceLocationsPipelinelocalf: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPipelinelocalf, LocationsPipelinelocalfSlice](mysql.PreloadRel{ + Name: "SpaceLocationsPipelinelocalf", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsPipelinelocalfs, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsPipelinelocalfs.Columns.Names(), opts...) + }, + SpaceLocationsRclone: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsRclone, LocationsRcloneSlice](mysql.PreloadRel{ + Name: "SpaceLocationsRclone", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsRclones, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsRclones.Columns.Names(), opts...) + }, + SpaceLocationsS3: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsS3, LocationsS3Slice](mysql.PreloadRel{ + Name: "SpaceLocationsS3", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsS3S, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsS3S.Columns.Names(), opts...) + }, + SpaceLocationsSwift: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSwift, LocationsSwiftSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSwift", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsSwifts, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsSwifts.Columns.Names(), opts...) + }, + } +} + +type locationsSpaceThenLoader[Q orm.Loadable] struct { + SpaceLocationsArchipelago func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsArkivum func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsDataverse func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsDspace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsDspacerest func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsDuracloud func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsFedora func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsGPG func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsLocalfilesystem func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsLocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsLockssomatic func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsNF func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsOfflinereplicastaging func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsPipelinelocalf func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsRclone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsS3 func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsSwift func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsSpaceThenLoader[Q orm.Loadable]() locationsSpaceThenLoader[Q] { + type SpaceLocationsArchipelagoLoadInterface interface { + LoadSpaceLocationsArchipelago(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsArkivumLoadInterface interface { + LoadSpaceLocationsArkivum(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsDataverseLoadInterface interface { + LoadSpaceLocationsDataverse(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsDspaceLoadInterface interface { + LoadSpaceLocationsDspace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsDspacerestLoadInterface interface { + LoadSpaceLocationsDspacerest(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsDuracloudLoadInterface interface { + LoadSpaceLocationsDuracloud(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsFedoraLoadInterface interface { + LoadSpaceLocationsFedora(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsGPGLoadInterface interface { + LoadSpaceLocationsGPG(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsLocalfilesystemLoadInterface interface { + LoadSpaceLocationsLocalfilesystem(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsLocationsLoadInterface interface { + LoadSpaceLocationsLocations(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsLockssomaticLoadInterface interface { + LoadSpaceLocationsLockssomatic(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsNFLoadInterface interface { + LoadSpaceLocationsNF(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsOfflinereplicastagingLoadInterface interface { + LoadSpaceLocationsOfflinereplicastaging(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsPipelinelocalfLoadInterface interface { + LoadSpaceLocationsPipelinelocalf(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsRcloneLoadInterface interface { + LoadSpaceLocationsRclone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsS3LoadInterface interface { + LoadSpaceLocationsS3(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsSwiftLoadInterface interface { + LoadSpaceLocationsSwift(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsSpaceThenLoader[Q]{ + SpaceLocationsArchipelago: thenLoadBuilder[Q]( + "SpaceLocationsArchipelago", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsArchipelagoLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsArchipelago(ctx, exec, mods...) + }, + ), + SpaceLocationsArkivum: thenLoadBuilder[Q]( + "SpaceLocationsArkivum", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsArkivumLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsArkivum(ctx, exec, mods...) + }, + ), + SpaceLocationsDataverse: thenLoadBuilder[Q]( + "SpaceLocationsDataverse", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsDataverseLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsDataverse(ctx, exec, mods...) + }, + ), + SpaceLocationsDspace: thenLoadBuilder[Q]( + "SpaceLocationsDspace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsDspaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsDspace(ctx, exec, mods...) + }, + ), + SpaceLocationsDspacerest: thenLoadBuilder[Q]( + "SpaceLocationsDspacerest", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsDspacerestLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsDspacerest(ctx, exec, mods...) + }, + ), + SpaceLocationsDuracloud: thenLoadBuilder[Q]( + "SpaceLocationsDuracloud", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsDuracloudLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsDuracloud(ctx, exec, mods...) + }, + ), + SpaceLocationsFedora: thenLoadBuilder[Q]( + "SpaceLocationsFedora", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsFedoraLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsFedora(ctx, exec, mods...) + }, + ), + SpaceLocationsGPG: thenLoadBuilder[Q]( + "SpaceLocationsGPG", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsGPGLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsGPG(ctx, exec, mods...) + }, + ), + SpaceLocationsLocalfilesystem: thenLoadBuilder[Q]( + "SpaceLocationsLocalfilesystem", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsLocalfilesystemLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsLocalfilesystem(ctx, exec, mods...) + }, + ), + SpaceLocationsLocations: thenLoadBuilder[Q]( + "SpaceLocationsLocations", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsLocationsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsLocations(ctx, exec, mods...) + }, + ), + SpaceLocationsLockssomatic: thenLoadBuilder[Q]( + "SpaceLocationsLockssomatic", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsLockssomaticLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsLockssomatic(ctx, exec, mods...) + }, + ), + SpaceLocationsNF: thenLoadBuilder[Q]( + "SpaceLocationsNF", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsNFLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsNF(ctx, exec, mods...) + }, + ), + SpaceLocationsOfflinereplicastaging: thenLoadBuilder[Q]( + "SpaceLocationsOfflinereplicastaging", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsOfflinereplicastagingLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsOfflinereplicastaging(ctx, exec, mods...) + }, + ), + SpaceLocationsPipelinelocalf: thenLoadBuilder[Q]( + "SpaceLocationsPipelinelocalf", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsPipelinelocalfLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsPipelinelocalf(ctx, exec, mods...) + }, + ), + SpaceLocationsRclone: thenLoadBuilder[Q]( + "SpaceLocationsRclone", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsRcloneLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsRclone(ctx, exec, mods...) + }, + ), + SpaceLocationsS3: thenLoadBuilder[Q]( + "SpaceLocationsS3", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsS3LoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsS3(ctx, exec, mods...) + }, + ), + SpaceLocationsSwift: thenLoadBuilder[Q]( + "SpaceLocationsSwift", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSwiftLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSwift(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsArchipelago loads the locationsSpace's SpaceLocationsArchipelago into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsArchipelago(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsArchipelago = nil + + related, err := o.SpaceLocationsArchipelago(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsArchipelago = related + return nil +} + +// LoadSpaceLocationsArchipelago loads the locationsSpace's SpaceLocationsArchipelago into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsArchipelago(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsArchipelagos, err := os.SpaceLocationsArchipelago(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsArchipelagos { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsArchipelago = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsArkivum loads the locationsSpace's SpaceLocationsArkivum into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsArkivum(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsArkivum = nil + + related, err := o.SpaceLocationsArkivum(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsArkivum = related + return nil +} + +// LoadSpaceLocationsArkivum loads the locationsSpace's SpaceLocationsArkivum into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsArkivum(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsArkivums, err := os.SpaceLocationsArkivum(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsArkivums { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsArkivum = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsDataverse loads the locationsSpace's SpaceLocationsDataverse into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsDataverse(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsDataverse = nil + + related, err := o.SpaceLocationsDataverse(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsDataverse = related + return nil +} + +// LoadSpaceLocationsDataverse loads the locationsSpace's SpaceLocationsDataverse into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsDataverse(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsDataverses, err := os.SpaceLocationsDataverse(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsDataverses { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsDataverse = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsDspace loads the locationsSpace's SpaceLocationsDspace into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsDspace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsDspace = nil + + related, err := o.SpaceLocationsDspace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsDspace = related + return nil +} + +// LoadSpaceLocationsDspace loads the locationsSpace's SpaceLocationsDspace into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsDspace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsDspaces, err := os.SpaceLocationsDspace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsDspaces { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsDspace = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsDspacerest loads the locationsSpace's SpaceLocationsDspacerest into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsDspacerest(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsDspacerest = nil + + related, err := o.SpaceLocationsDspacerest(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsDspacerest = related + return nil +} + +// LoadSpaceLocationsDspacerest loads the locationsSpace's SpaceLocationsDspacerest into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsDspacerest(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsDspacerests, err := os.SpaceLocationsDspacerest(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsDspacerests { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsDspacerest = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsDuracloud loads the locationsSpace's SpaceLocationsDuracloud into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsDuracloud(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsDuracloud = nil + + related, err := o.SpaceLocationsDuracloud(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsDuracloud = related + return nil +} + +// LoadSpaceLocationsDuracloud loads the locationsSpace's SpaceLocationsDuracloud into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsDuracloud(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsDuraclouds, err := os.SpaceLocationsDuracloud(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsDuraclouds { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsDuracloud = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsFedora loads the locationsSpace's SpaceLocationsFedora into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsFedora(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsFedora = nil + + related, err := o.SpaceLocationsFedora(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsFedora = related + return nil +} + +// LoadSpaceLocationsFedora loads the locationsSpace's SpaceLocationsFedora into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsFedora(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsFedoras, err := os.SpaceLocationsFedora(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsFedoras { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsFedora = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsGPG loads the locationsSpace's SpaceLocationsGPG into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsGPG(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsGPG = nil + + related, err := o.SpaceLocationsGPG(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsGPG = related + return nil +} + +// LoadSpaceLocationsGPG loads the locationsSpace's SpaceLocationsGPG into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsGPG(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsGPGS, err := os.SpaceLocationsGPG(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsGPGS { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsGPG = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsLocalfilesystem loads the locationsSpace's SpaceLocationsLocalfilesystem into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsLocalfilesystem(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsLocalfilesystem = nil + + related, err := o.SpaceLocationsLocalfilesystem(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsLocalfilesystem = related + return nil +} + +// LoadSpaceLocationsLocalfilesystem loads the locationsSpace's SpaceLocationsLocalfilesystem into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsLocalfilesystem(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocalfilesystems, err := os.SpaceLocationsLocalfilesystem(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocalfilesystems { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsLocalfilesystem = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsLocations loads the locationsSpace's SpaceLocationsLocations into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsLocations(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsLocations = nil + + related, err := o.SpaceLocationsLocations(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.SpaceLocationsSpace = o + } + + o.R.SpaceLocationsLocations = related + return nil +} + +// LoadSpaceLocationsLocations loads the locationsSpace's SpaceLocationsLocations into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsLocations(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocations, err := os.SpaceLocationsLocations(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.SpaceLocationsLocations = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocations { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsLocations = append(o.R.SpaceLocationsLocations, rel) + } + } + + return nil +} + +// LoadSpaceLocationsLockssomatic loads the locationsSpace's SpaceLocationsLockssomatic into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsLockssomatic(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsLockssomatic = nil + + related, err := o.SpaceLocationsLockssomatic(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsLockssomatic = related + return nil +} + +// LoadSpaceLocationsLockssomatic loads the locationsSpace's SpaceLocationsLockssomatic into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsLockssomatic(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLockssomatics, err := os.SpaceLocationsLockssomatic(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLockssomatics { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsLockssomatic = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsNF loads the locationsSpace's SpaceLocationsNF into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsNF(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsNF = nil + + related, err := o.SpaceLocationsNF(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsNF = related + return nil +} + +// LoadSpaceLocationsNF loads the locationsSpace's SpaceLocationsNF into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsNF(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsNFS, err := os.SpaceLocationsNF(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsNFS { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsNF = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsOfflinereplicastaging loads the locationsSpace's SpaceLocationsOfflinereplicastaging into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsOfflinereplicastaging(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsOfflinereplicastaging = nil + + related, err := o.SpaceLocationsOfflinereplicastaging(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsOfflinereplicastaging = related + return nil +} + +// LoadSpaceLocationsOfflinereplicastaging loads the locationsSpace's SpaceLocationsOfflinereplicastaging into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsOfflinereplicastaging(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsOfflinereplicastagings, err := os.SpaceLocationsOfflinereplicastaging(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsOfflinereplicastagings { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsOfflinereplicastaging = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsPipelinelocalf loads the locationsSpace's SpaceLocationsPipelinelocalf into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsPipelinelocalf(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsPipelinelocalf = nil + + related, err := o.SpaceLocationsPipelinelocalf(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsPipelinelocalf = related + return nil +} + +// LoadSpaceLocationsPipelinelocalf loads the locationsSpace's SpaceLocationsPipelinelocalf into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsPipelinelocalf(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPipelinelocalfs, err := os.SpaceLocationsPipelinelocalf(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPipelinelocalfs { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsPipelinelocalf = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsRclone loads the locationsSpace's SpaceLocationsRclone into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsRclone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsRclone = nil + + related, err := o.SpaceLocationsRclone(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsRclone = related + return nil +} + +// LoadSpaceLocationsRclone loads the locationsSpace's SpaceLocationsRclone into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsRclone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsRclones, err := os.SpaceLocationsRclone(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsRclones { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsRclone = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsS3 loads the locationsSpace's SpaceLocationsS3 into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsS3(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsS3 = nil + + related, err := o.SpaceLocationsS3(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsS3 = related + return nil +} + +// LoadSpaceLocationsS3 loads the locationsSpace's SpaceLocationsS3 into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsS3(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsS3S, err := os.SpaceLocationsS3(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsS3S { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsS3 = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsSwift loads the locationsSpace's SpaceLocationsSwift into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsSwift(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSwift = nil + + related, err := o.SpaceLocationsSwift(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsSwift = related + return nil +} + +// LoadSpaceLocationsSwift loads the locationsSpace's SpaceLocationsSwift into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsSwift(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSwifts, err := os.SpaceLocationsSwift(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSwifts { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsSwift = rel + break + } + } + + return nil +} + +type locationsSpaceJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsArchipelago modAs[Q, locationsArchipelagoColumns] + SpaceLocationsArkivum modAs[Q, locationsArkivumColumns] + SpaceLocationsDataverse modAs[Q, locationsDataverseColumns] + SpaceLocationsDspace modAs[Q, locationsDspaceColumns] + SpaceLocationsDspacerest modAs[Q, locationsDspacerestColumns] + SpaceLocationsDuracloud modAs[Q, locationsDuracloudColumns] + SpaceLocationsFedora modAs[Q, locationsFedoraColumns] + SpaceLocationsGPG modAs[Q, locationsGPGColumns] + SpaceLocationsLocalfilesystem modAs[Q, locationsLocalfilesystemColumns] + SpaceLocationsLocations modAs[Q, locationsLocationColumns] + SpaceLocationsLockssomatic modAs[Q, locationsLockssomaticColumns] + SpaceLocationsNF modAs[Q, locationsNFColumns] + SpaceLocationsOfflinereplicastaging modAs[Q, locationsOfflinereplicastagingColumns] + SpaceLocationsPipelinelocalf modAs[Q, locationsPipelinelocalfColumns] + SpaceLocationsRclone modAs[Q, locationsRcloneColumns] + SpaceLocationsS3 modAs[Q, locationsS3Columns] + SpaceLocationsSwift modAs[Q, locationsSwiftColumns] +} + +func (j locationsSpaceJoins[Q]) aliasedAs(alias string) locationsSpaceJoins[Q] { + return buildLocationsSpaceJoins[Q](buildLocationsSpaceColumns(alias), j.typ) +} + +func buildLocationsSpaceJoins[Q dialect.Joinable](cols locationsSpaceColumns, typ string) locationsSpaceJoins[Q] { + return locationsSpaceJoins[Q]{ + typ: typ, + SpaceLocationsArchipelago: modAs[Q, locationsArchipelagoColumns]{ + c: LocationsArchipelagos.Columns, + f: func(to locationsArchipelagoColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsArchipelagos.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsArkivum: modAs[Q, locationsArkivumColumns]{ + c: LocationsArkivums.Columns, + f: func(to locationsArkivumColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsArkivums.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsDataverse: modAs[Q, locationsDataverseColumns]{ + c: LocationsDataverses.Columns, + f: func(to locationsDataverseColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsDataverses.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsDspace: modAs[Q, locationsDspaceColumns]{ + c: LocationsDspaces.Columns, + f: func(to locationsDspaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsDspaces.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsDspacerest: modAs[Q, locationsDspacerestColumns]{ + c: LocationsDspacerests.Columns, + f: func(to locationsDspacerestColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsDspacerests.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsDuracloud: modAs[Q, locationsDuracloudColumns]{ + c: LocationsDuraclouds.Columns, + f: func(to locationsDuracloudColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsDuraclouds.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsFedora: modAs[Q, locationsFedoraColumns]{ + c: LocationsFedoras.Columns, + f: func(to locationsFedoraColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsFedoras.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsGPG: modAs[Q, locationsGPGColumns]{ + c: LocationsGPGS.Columns, + f: func(to locationsGPGColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsGPGS.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsLocalfilesystem: modAs[Q, locationsLocalfilesystemColumns]{ + c: LocationsLocalfilesystems.Columns, + f: func(to locationsLocalfilesystemColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocalfilesystems.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsLocations: modAs[Q, locationsLocationColumns]{ + c: LocationsLocations.Columns, + f: func(to locationsLocationColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocations.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsLockssomatic: modAs[Q, locationsLockssomaticColumns]{ + c: LocationsLockssomatics.Columns, + f: func(to locationsLockssomaticColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLockssomatics.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsNF: modAs[Q, locationsNFColumns]{ + c: LocationsNFS.Columns, + f: func(to locationsNFColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsNFS.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsOfflinereplicastaging: modAs[Q, locationsOfflinereplicastagingColumns]{ + c: LocationsOfflinereplicastagings.Columns, + f: func(to locationsOfflinereplicastagingColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsOfflinereplicastagings.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsPipelinelocalf: modAs[Q, locationsPipelinelocalfColumns]{ + c: LocationsPipelinelocalfs.Columns, + f: func(to locationsPipelinelocalfColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPipelinelocalfs.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsRclone: modAs[Q, locationsRcloneColumns]{ + c: LocationsRclones.Columns, + f: func(to locationsRcloneColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsRclones.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsS3: modAs[Q, locationsS3Columns]{ + c: LocationsS3S.Columns, + f: func(to locationsS3Columns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsS3S.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsSwift: modAs[Q, locationsSwiftColumns]{ + c: LocationsSwifts.Columns, + f: func(to locationsSwiftColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSwifts.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/locations_swift.bob.go b/database/mcp/models/locations_swift.bob.go new file mode 100644 index 0000000..0327196 --- /dev/null +++ b/database/mcp/models/locations_swift.bob.go @@ -0,0 +1,762 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsSwift is an object representing the database table. +type LocationsSwift struct { + ID int32 `db:"id,pk,autoincr" ` + AuthURL string `db:"auth_url" ` + AuthVersion string `db:"auth_version" ` + Username string `db:"username" ` + Password string `db:"password" ` + Container string `db:"container" ` + Tenant null.Val[string] `db:"tenant" ` + Region null.Val[string] `db:"region" ` + SpaceID string `db:"space_id" ` + + R locationsSwiftR `db:"-" ` +} + +// LocationsSwiftSlice is an alias for a slice of pointers to LocationsSwift. +// This should almost always be used instead of []*LocationsSwift. +type LocationsSwiftSlice []*LocationsSwift + +// LocationsSwifts contains methods to work with the locations_swift table +var LocationsSwifts = mysql.NewTablex[*LocationsSwift, LocationsSwiftSlice, *LocationsSwiftSetter]("locations_swift", buildLocationsSwiftColumns("locations_swift"), []string{"id"}, []string{"space_id"}) + +// LocationsSwiftsQuery is a query on the locations_swift table +type LocationsSwiftsQuery = *mysql.ViewQuery[*LocationsSwift, LocationsSwiftSlice] + +// locationsSwiftR is where relationships are stored. +type locationsSwiftR struct { + SpaceLocationsSpace *LocationsSpace // locations_swift_space_id_9cfded49_fk_locations_space_uuid +} + +func buildLocationsSwiftColumns(alias string) locationsSwiftColumns { + return locationsSwiftColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "auth_url", "auth_version", "username", "password", "container", "tenant", "region", "space_id", + ).WithParent("locations_swift"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + AuthURL: mysql.Quote(alias, "auth_url"), + AuthVersion: mysql.Quote(alias, "auth_version"), + Username: mysql.Quote(alias, "username"), + Password: mysql.Quote(alias, "password"), + Container: mysql.Quote(alias, "container"), + Tenant: mysql.Quote(alias, "tenant"), + Region: mysql.Quote(alias, "region"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsSwiftColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + AuthURL mysql.Expression + AuthVersion mysql.Expression + Username mysql.Expression + Password mysql.Expression + Container mysql.Expression + Tenant mysql.Expression + Region mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsSwiftColumns) Alias() string { + return c.tableAlias +} + +func (locationsSwiftColumns) AliasedAs(alias string) locationsSwiftColumns { + return buildLocationsSwiftColumns(alias) +} + +// LocationsSwiftSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsSwiftSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + AuthURL omit.Val[string] `db:"auth_url" ` + AuthVersion omit.Val[string] `db:"auth_version" ` + Username omit.Val[string] `db:"username" ` + Password omit.Val[string] `db:"password" ` + Container omit.Val[string] `db:"container" ` + Tenant omitnull.Val[string] `db:"tenant" ` + Region omitnull.Val[string] `db:"region" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsSwiftSetter) SetColumns() []string { + vals := make([]string, 0, 9) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.AuthURL.IsValue() { + vals = append(vals, "auth_url") + } + if s.AuthVersion.IsValue() { + vals = append(vals, "auth_version") + } + if s.Username.IsValue() { + vals = append(vals, "username") + } + if s.Password.IsValue() { + vals = append(vals, "password") + } + if s.Container.IsValue() { + vals = append(vals, "container") + } + if !s.Tenant.IsUnset() { + vals = append(vals, "tenant") + } + if !s.Region.IsUnset() { + vals = append(vals, "region") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsSwiftSetter) Overwrite(t *LocationsSwift) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.AuthURL.IsValue() { + t.AuthURL = s.AuthURL.MustGet() + } + if s.AuthVersion.IsValue() { + t.AuthVersion = s.AuthVersion.MustGet() + } + if s.Username.IsValue() { + t.Username = s.Username.MustGet() + } + if s.Password.IsValue() { + t.Password = s.Password.MustGet() + } + if s.Container.IsValue() { + t.Container = s.Container.MustGet() + } + if !s.Tenant.IsUnset() { + t.Tenant = s.Tenant.MustGetNull() + } + if !s.Region.IsUnset() { + t.Region = s.Region.MustGetNull() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsSwiftSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsSwifts.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AuthURL.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AuthURL.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AuthVersion.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AuthVersion.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Username.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Username.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Password.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Password.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Container.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Container.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Tenant.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Tenant.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Region.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Region.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsSwiftSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_swift")...) +} + +func (s LocationsSwiftSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 9) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.AuthURL.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "auth_url")...), + mysql.Arg(s.AuthURL), + }}) + } + + if s.AuthVersion.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "auth_version")...), + mysql.Arg(s.AuthVersion), + }}) + } + + if s.Username.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "username")...), + mysql.Arg(s.Username), + }}) + } + + if s.Password.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "password")...), + mysql.Arg(s.Password), + }}) + } + + if s.Container.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "container")...), + mysql.Arg(s.Container), + }}) + } + + if !s.Tenant.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "tenant")...), + mysql.Arg(s.Tenant), + }}) + } + + if !s.Region.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "region")...), + mysql.Arg(s.Region), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsSwift retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsSwift(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsSwift, error) { + if len(cols) == 0 { + return LocationsSwifts.Query( + sm.Where(LocationsSwifts.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsSwifts.Query( + sm.Where(LocationsSwifts.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsSwifts.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsSwiftExists checks the presence of a single record by primary key +func LocationsSwiftExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsSwifts.Query( + sm.Where(LocationsSwifts.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsSwift is retrieved from the database +func (o *LocationsSwift) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsSwifts.AfterSelectHooks.RunHooks(ctx, exec, LocationsSwiftSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsSwifts.AfterInsertHooks.RunHooks(ctx, exec, LocationsSwiftSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsSwifts.AfterUpdateHooks.RunHooks(ctx, exec, LocationsSwiftSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsSwifts.AfterDeleteHooks.RunHooks(ctx, exec, LocationsSwiftSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsSwift +func (o *LocationsSwift) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsSwift) pkEQ() dialect.Expression { + return mysql.Quote("locations_swift", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsSwift +func (o *LocationsSwift) Update(ctx context.Context, exec bob.Executor, s *LocationsSwiftSetter) error { + _, err := LocationsSwifts.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsSwift record with an executor +func (o *LocationsSwift) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsSwifts.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsSwift using the executor +func (o *LocationsSwift) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsSwifts.Query( + sm.Where(LocationsSwifts.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsSwiftSlice is retrieved from the database +func (o LocationsSwiftSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsSwifts.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsSwifts.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsSwifts.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsSwifts.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsSwiftSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_swift", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsSwiftSlice) copyMatchingRows(from ...*LocationsSwift) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsSwiftSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsSwifts.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsSwift: + o.copyMatchingRows(retrieved) + case []*LocationsSwift: + o.copyMatchingRows(retrieved...) + case LocationsSwiftSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsSwift or a slice of LocationsSwift + // then run the AfterUpdateHooks on the slice + _, err = LocationsSwifts.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsSwiftSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsSwifts.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsSwift: + o.copyMatchingRows(retrieved) + case []*LocationsSwift: + o.copyMatchingRows(retrieved...) + case LocationsSwiftSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsSwift or a slice of LocationsSwift + // then run the AfterDeleteHooks on the slice + _, err = LocationsSwifts.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsSwiftSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsSwiftSetter) error { + _, err := LocationsSwifts.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsSwiftSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsSwifts.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsSwiftSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsSwifts.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsSwift) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsSwiftSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsSwiftSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsSwift0 *LocationsSwift, locationsSpace1 *LocationsSpace) (*LocationsSwift, error) { + setter := &LocationsSwiftSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsSwift0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSwiftSpaceLocationsSpace0: %w", err) + } + + return locationsSwift0, nil +} + +func (locationsSwift0 *LocationsSwift) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsSwiftSpaceLocationsSpace0(ctx, exec, 1, locationsSwift0, locationsSpace1) + if err != nil { + return err + } + + locationsSwift0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsSwift = locationsSwift0 + + return nil +} + +func (locationsSwift0 *LocationsSwift) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsSwiftSpaceLocationsSpace0(ctx, exec, 1, locationsSwift0, locationsSpace1) + if err != nil { + return err + } + + locationsSwift0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsSwift = locationsSwift0 + + return nil +} + +type locationsSwiftWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + AuthURL mysql.WhereMod[Q, string] + AuthVersion mysql.WhereMod[Q, string] + Username mysql.WhereMod[Q, string] + Password mysql.WhereMod[Q, string] + Container mysql.WhereMod[Q, string] + Tenant mysql.WhereNullMod[Q, string] + Region mysql.WhereNullMod[Q, string] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsSwiftWhere[Q]) AliasedAs(alias string) locationsSwiftWhere[Q] { + return buildLocationsSwiftWhere[Q](buildLocationsSwiftColumns(alias)) +} + +func buildLocationsSwiftWhere[Q mysql.Filterable](cols locationsSwiftColumns) locationsSwiftWhere[Q] { + return locationsSwiftWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + AuthURL: mysql.Where[Q, string](cols.AuthURL), + AuthVersion: mysql.Where[Q, string](cols.AuthVersion), + Username: mysql.Where[Q, string](cols.Username), + Password: mysql.Where[Q, string](cols.Password), + Container: mysql.Where[Q, string](cols.Container), + Tenant: mysql.WhereNull[Q, string](cols.Tenant), + Region: mysql.WhereNull[Q, string](cols.Region), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsSwift) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsSwift cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsSwift = o + } + return nil + default: + return fmt.Errorf("locationsSwift has no relationship %q", name) + } +} + +type locationsSwiftPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsSwiftPreloader() locationsSwiftPreloader { + return locationsSwiftPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsSwifts, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsSwiftThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsSwiftThenLoader[Q orm.Loadable]() locationsSwiftThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsSwiftThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsSwift's SpaceLocationsSpace into the .R struct +func (o *LocationsSwift) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSwift = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsSwift's SpaceLocationsSpace into the .R struct +func (os LocationsSwiftSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsSwift = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsSwiftJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsSwiftJoins[Q]) aliasedAs(alias string) locationsSwiftJoins[Q] { + return buildLocationsSwiftJoins[Q](buildLocationsSwiftColumns(alias), j.typ) +} + +func buildLocationsSwiftJoins[Q dialect.Joinable](cols locationsSwiftColumns, typ string) locationsSwiftJoins[Q] { + return locationsSwiftJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/mcp/models/tastypie_apiaccess.bob.go b/database/mcp/models/tastypie_apiaccess.bob.go new file mode 100644 index 0000000..b7a15a5 --- /dev/null +++ b/database/mcp/models/tastypie_apiaccess.bob.go @@ -0,0 +1,442 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" +) + +// TastypieApiaccess is an object representing the database table. +type TastypieApiaccess struct { + ID int32 `db:"id,pk,autoincr" ` + Identifier string `db:"identifier" ` + URL string `db:"url" ` + RequestMethod string `db:"request_method" ` + Accessed uint32 `db:"accessed" ` +} + +// TastypieApiaccessSlice is an alias for a slice of pointers to TastypieApiaccess. +// This should almost always be used instead of []*TastypieApiaccess. +type TastypieApiaccessSlice []*TastypieApiaccess + +// TastypieApiaccesses contains methods to work with the tastypie_apiaccess table +var TastypieApiaccesses = mysql.NewTablex[*TastypieApiaccess, TastypieApiaccessSlice, *TastypieApiaccessSetter]("tastypie_apiaccess", buildTastypieApiaccessColumns("tastypie_apiaccess"), []string{"id"}) + +// TastypieApiaccessesQuery is a query on the tastypie_apiaccess table +type TastypieApiaccessesQuery = *mysql.ViewQuery[*TastypieApiaccess, TastypieApiaccessSlice] + +func buildTastypieApiaccessColumns(alias string) tastypieApiaccessColumns { + return tastypieApiaccessColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "identifier", "url", "request_method", "accessed", + ).WithParent("tastypie_apiaccess"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Identifier: mysql.Quote(alias, "identifier"), + URL: mysql.Quote(alias, "url"), + RequestMethod: mysql.Quote(alias, "request_method"), + Accessed: mysql.Quote(alias, "accessed"), + } +} + +type tastypieApiaccessColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Identifier mysql.Expression + URL mysql.Expression + RequestMethod mysql.Expression + Accessed mysql.Expression +} + +func (c tastypieApiaccessColumns) Alias() string { + return c.tableAlias +} + +func (tastypieApiaccessColumns) AliasedAs(alias string) tastypieApiaccessColumns { + return buildTastypieApiaccessColumns(alias) +} + +// TastypieApiaccessSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type TastypieApiaccessSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Identifier omit.Val[string] `db:"identifier" ` + URL omit.Val[string] `db:"url" ` + RequestMethod omit.Val[string] `db:"request_method" ` + Accessed omit.Val[uint32] `db:"accessed" ` +} + +func (s TastypieApiaccessSetter) SetColumns() []string { + vals := make([]string, 0, 5) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Identifier.IsValue() { + vals = append(vals, "identifier") + } + if s.URL.IsValue() { + vals = append(vals, "url") + } + if s.RequestMethod.IsValue() { + vals = append(vals, "request_method") + } + if s.Accessed.IsValue() { + vals = append(vals, "accessed") + } + return vals +} + +func (s TastypieApiaccessSetter) Overwrite(t *TastypieApiaccess) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Identifier.IsValue() { + t.Identifier = s.Identifier.MustGet() + } + if s.URL.IsValue() { + t.URL = s.URL.MustGet() + } + if s.RequestMethod.IsValue() { + t.RequestMethod = s.RequestMethod.MustGet() + } + if s.Accessed.IsValue() { + t.Accessed = s.Accessed.MustGet() + } +} + +func (s *TastypieApiaccessSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return TastypieApiaccesses.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Identifier.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Identifier.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.URL.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.URL.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.RequestMethod.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RequestMethod.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Accessed.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Accessed.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s TastypieApiaccessSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("tastypie_apiaccess")...) +} + +func (s TastypieApiaccessSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 5) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Identifier.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "identifier")...), + mysql.Arg(s.Identifier), + }}) + } + + if s.URL.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "url")...), + mysql.Arg(s.URL), + }}) + } + + if s.RequestMethod.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "request_method")...), + mysql.Arg(s.RequestMethod), + }}) + } + + if s.Accessed.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "accessed")...), + mysql.Arg(s.Accessed), + }}) + } + + return exprs +} + +// FindTastypieApiaccess retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindTastypieApiaccess(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*TastypieApiaccess, error) { + if len(cols) == 0 { + return TastypieApiaccesses.Query( + sm.Where(TastypieApiaccesses.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return TastypieApiaccesses.Query( + sm.Where(TastypieApiaccesses.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(TastypieApiaccesses.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// TastypieApiaccessExists checks the presence of a single record by primary key +func TastypieApiaccessExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return TastypieApiaccesses.Query( + sm.Where(TastypieApiaccesses.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after TastypieApiaccess is retrieved from the database +func (o *TastypieApiaccess) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = TastypieApiaccesses.AfterSelectHooks.RunHooks(ctx, exec, TastypieApiaccessSlice{o}) + case bob.QueryTypeInsert: + ctx, err = TastypieApiaccesses.AfterInsertHooks.RunHooks(ctx, exec, TastypieApiaccessSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = TastypieApiaccesses.AfterUpdateHooks.RunHooks(ctx, exec, TastypieApiaccessSlice{o}) + case bob.QueryTypeDelete: + ctx, err = TastypieApiaccesses.AfterDeleteHooks.RunHooks(ctx, exec, TastypieApiaccessSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the TastypieApiaccess +func (o *TastypieApiaccess) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *TastypieApiaccess) pkEQ() dialect.Expression { + return mysql.Quote("tastypie_apiaccess", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the TastypieApiaccess +func (o *TastypieApiaccess) Update(ctx context.Context, exec bob.Executor, s *TastypieApiaccessSetter) error { + _, err := TastypieApiaccesses.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single TastypieApiaccess record with an executor +func (o *TastypieApiaccess) Delete(ctx context.Context, exec bob.Executor) error { + _, err := TastypieApiaccesses.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the TastypieApiaccess using the executor +func (o *TastypieApiaccess) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := TastypieApiaccesses.Query( + sm.Where(TastypieApiaccesses.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + + *o = *o2 + + return nil +} + +// AfterQueryHook is called after TastypieApiaccessSlice is retrieved from the database +func (o TastypieApiaccessSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = TastypieApiaccesses.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = TastypieApiaccesses.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = TastypieApiaccesses.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = TastypieApiaccesses.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o TastypieApiaccessSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("tastypie_apiaccess", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o TastypieApiaccessSlice) copyMatchingRows(from ...*TastypieApiaccess) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o TastypieApiaccessSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return TastypieApiaccesses.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *TastypieApiaccess: + o.copyMatchingRows(retrieved) + case []*TastypieApiaccess: + o.copyMatchingRows(retrieved...) + case TastypieApiaccessSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a TastypieApiaccess or a slice of TastypieApiaccess + // then run the AfterUpdateHooks on the slice + _, err = TastypieApiaccesses.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o TastypieApiaccessSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return TastypieApiaccesses.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *TastypieApiaccess: + o.copyMatchingRows(retrieved) + case []*TastypieApiaccess: + o.copyMatchingRows(retrieved...) + case TastypieApiaccessSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a TastypieApiaccess or a slice of TastypieApiaccess + // then run the AfterDeleteHooks on the slice + _, err = TastypieApiaccesses.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o TastypieApiaccessSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals TastypieApiaccessSetter) error { + _, err := TastypieApiaccesses.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o TastypieApiaccessSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := TastypieApiaccesses.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o TastypieApiaccessSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := TastypieApiaccesses.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +type tastypieApiaccessWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Identifier mysql.WhereMod[Q, string] + URL mysql.WhereMod[Q, string] + RequestMethod mysql.WhereMod[Q, string] + Accessed mysql.WhereMod[Q, uint32] +} + +func (tastypieApiaccessWhere[Q]) AliasedAs(alias string) tastypieApiaccessWhere[Q] { + return buildTastypieApiaccessWhere[Q](buildTastypieApiaccessColumns(alias)) +} + +func buildTastypieApiaccessWhere[Q mysql.Filterable](cols tastypieApiaccessColumns) tastypieApiaccessWhere[Q] { + return tastypieApiaccessWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Identifier: mysql.Where[Q, string](cols.Identifier), + URL: mysql.Where[Q, string](cols.URL), + RequestMethod: mysql.Where[Q, string](cols.RequestMethod), + Accessed: mysql.Where[Q, uint32](cols.Accessed), + } +} diff --git a/database/mcp/models/tastypie_apikey.bob.go b/database/mcp/models/tastypie_apikey.bob.go new file mode 100644 index 0000000..fc877a8 --- /dev/null +++ b/database/mcp/models/tastypie_apikey.bob.go @@ -0,0 +1,641 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// TastypieApikey is an object representing the database table. +type TastypieApikey struct { + ID int32 `db:"id,pk,autoincr" ` + Key string `db:"key" ` + Created time.Time `db:"created" ` + UserID int32 `db:"user_id" ` + + R tastypieApikeyR `db:"-" ` +} + +// TastypieApikeySlice is an alias for a slice of pointers to TastypieApikey. +// This should almost always be used instead of []*TastypieApikey. +type TastypieApikeySlice []*TastypieApikey + +// TastypieApikeys contains methods to work with the tastypie_apikey table +var TastypieApikeys = mysql.NewTablex[*TastypieApikey, TastypieApikeySlice, *TastypieApikeySetter]("tastypie_apikey", buildTastypieApikeyColumns("tastypie_apikey"), []string{"id"}, []string{"user_id"}) + +// TastypieApikeysQuery is a query on the tastypie_apikey table +type TastypieApikeysQuery = *mysql.ViewQuery[*TastypieApikey, TastypieApikeySlice] + +// tastypieApikeyR is where relationships are stored. +type tastypieApikeyR struct { + UserAuthUser *AuthUser // tastypie_apikey_user_id_8c8fa920_fk_auth_user_id +} + +func buildTastypieApikeyColumns(alias string) tastypieApikeyColumns { + return tastypieApikeyColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "key", "created", "user_id", + ).WithParent("tastypie_apikey"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Key: mysql.Quote(alias, "key"), + Created: mysql.Quote(alias, "created"), + UserID: mysql.Quote(alias, "user_id"), + } +} + +type tastypieApikeyColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Key mysql.Expression + Created mysql.Expression + UserID mysql.Expression +} + +func (c tastypieApikeyColumns) Alias() string { + return c.tableAlias +} + +func (tastypieApikeyColumns) AliasedAs(alias string) tastypieApikeyColumns { + return buildTastypieApikeyColumns(alias) +} + +// TastypieApikeySetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type TastypieApikeySetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Key omit.Val[string] `db:"key" ` + Created omit.Val[time.Time] `db:"created" ` + UserID omit.Val[int32] `db:"user_id" ` +} + +func (s TastypieApikeySetter) SetColumns() []string { + vals := make([]string, 0, 4) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Key.IsValue() { + vals = append(vals, "key") + } + if s.Created.IsValue() { + vals = append(vals, "created") + } + if s.UserID.IsValue() { + vals = append(vals, "user_id") + } + return vals +} + +func (s TastypieApikeySetter) Overwrite(t *TastypieApikey) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Key.IsValue() { + t.Key = s.Key.MustGet() + } + if s.Created.IsValue() { + t.Created = s.Created.MustGet() + } + if s.UserID.IsValue() { + t.UserID = s.UserID.MustGet() + } +} + +func (s *TastypieApikeySetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return TastypieApikeys.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Key.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Key.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Created.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Created.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UserID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UserID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s TastypieApikeySetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("tastypie_apikey")...) +} + +func (s TastypieApikeySetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 4) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Key.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "key")...), + mysql.Arg(s.Key), + }}) + } + + if s.Created.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "created")...), + mysql.Arg(s.Created), + }}) + } + + if s.UserID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "user_id")...), + mysql.Arg(s.UserID), + }}) + } + + return exprs +} + +// FindTastypieApikey retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindTastypieApikey(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*TastypieApikey, error) { + if len(cols) == 0 { + return TastypieApikeys.Query( + sm.Where(TastypieApikeys.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return TastypieApikeys.Query( + sm.Where(TastypieApikeys.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(TastypieApikeys.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// TastypieApikeyExists checks the presence of a single record by primary key +func TastypieApikeyExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return TastypieApikeys.Query( + sm.Where(TastypieApikeys.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after TastypieApikey is retrieved from the database +func (o *TastypieApikey) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = TastypieApikeys.AfterSelectHooks.RunHooks(ctx, exec, TastypieApikeySlice{o}) + case bob.QueryTypeInsert: + ctx, err = TastypieApikeys.AfterInsertHooks.RunHooks(ctx, exec, TastypieApikeySlice{o}) + case bob.QueryTypeUpdate: + ctx, err = TastypieApikeys.AfterUpdateHooks.RunHooks(ctx, exec, TastypieApikeySlice{o}) + case bob.QueryTypeDelete: + ctx, err = TastypieApikeys.AfterDeleteHooks.RunHooks(ctx, exec, TastypieApikeySlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the TastypieApikey +func (o *TastypieApikey) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *TastypieApikey) pkEQ() dialect.Expression { + return mysql.Quote("tastypie_apikey", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the TastypieApikey +func (o *TastypieApikey) Update(ctx context.Context, exec bob.Executor, s *TastypieApikeySetter) error { + _, err := TastypieApikeys.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single TastypieApikey record with an executor +func (o *TastypieApikey) Delete(ctx context.Context, exec bob.Executor) error { + _, err := TastypieApikeys.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the TastypieApikey using the executor +func (o *TastypieApikey) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := TastypieApikeys.Query( + sm.Where(TastypieApikeys.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after TastypieApikeySlice is retrieved from the database +func (o TastypieApikeySlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = TastypieApikeys.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = TastypieApikeys.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = TastypieApikeys.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = TastypieApikeys.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o TastypieApikeySlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("tastypie_apikey", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o TastypieApikeySlice) copyMatchingRows(from ...*TastypieApikey) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o TastypieApikeySlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return TastypieApikeys.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *TastypieApikey: + o.copyMatchingRows(retrieved) + case []*TastypieApikey: + o.copyMatchingRows(retrieved...) + case TastypieApikeySlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a TastypieApikey or a slice of TastypieApikey + // then run the AfterUpdateHooks on the slice + _, err = TastypieApikeys.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o TastypieApikeySlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return TastypieApikeys.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *TastypieApikey: + o.copyMatchingRows(retrieved) + case []*TastypieApikey: + o.copyMatchingRows(retrieved...) + case TastypieApikeySlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a TastypieApikey or a slice of TastypieApikey + // then run the AfterDeleteHooks on the slice + _, err = TastypieApikeys.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o TastypieApikeySlice) UpdateAll(ctx context.Context, exec bob.Executor, vals TastypieApikeySetter) error { + _, err := TastypieApikeys.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o TastypieApikeySlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := TastypieApikeys.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o TastypieApikeySlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := TastypieApikeys.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// UserAuthUser starts a query for related objects on auth_user +func (o *TastypieApikey) UserAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + return AuthUsers.Query(append(mods, + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(o.UserID))), + )...) +} + +func (os TastypieApikeySlice) UserAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UserID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUsers.Query(append(mods, + sm.Where(mysql.Group(AuthUsers.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func attachTastypieApikeyUserAuthUser0(ctx context.Context, exec bob.Executor, count int, tastypieApikey0 *TastypieApikey, authUser1 *AuthUser) (*TastypieApikey, error) { + setter := &TastypieApikeySetter{ + UserID: omit.From(authUser1.ID), + } + + err := tastypieApikey0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachTastypieApikeyUserAuthUser0: %w", err) + } + + return tastypieApikey0, nil +} + +func (tastypieApikey0 *TastypieApikey) InsertUserAuthUser(ctx context.Context, exec bob.Executor, related *AuthUserSetter) error { + var err error + + authUser1, err := AuthUsers.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachTastypieApikeyUserAuthUser0(ctx, exec, 1, tastypieApikey0, authUser1) + if err != nil { + return err + } + + tastypieApikey0.R.UserAuthUser = authUser1 + + authUser1.R.UserTastypieApikey = tastypieApikey0 + + return nil +} + +func (tastypieApikey0 *TastypieApikey) AttachUserAuthUser(ctx context.Context, exec bob.Executor, authUser1 *AuthUser) error { + var err error + + _, err = attachTastypieApikeyUserAuthUser0(ctx, exec, 1, tastypieApikey0, authUser1) + if err != nil { + return err + } + + tastypieApikey0.R.UserAuthUser = authUser1 + + authUser1.R.UserTastypieApikey = tastypieApikey0 + + return nil +} + +type tastypieApikeyWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Key mysql.WhereMod[Q, string] + Created mysql.WhereMod[Q, time.Time] + UserID mysql.WhereMod[Q, int32] +} + +func (tastypieApikeyWhere[Q]) AliasedAs(alias string) tastypieApikeyWhere[Q] { + return buildTastypieApikeyWhere[Q](buildTastypieApikeyColumns(alias)) +} + +func buildTastypieApikeyWhere[Q mysql.Filterable](cols tastypieApikeyColumns) tastypieApikeyWhere[Q] { + return tastypieApikeyWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Key: mysql.Where[Q, string](cols.Key), + Created: mysql.Where[Q, time.Time](cols.Created), + UserID: mysql.Where[Q, int32](cols.UserID), + } +} + +func (o *TastypieApikey) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "UserAuthUser": + rel, ok := retrieved.(*AuthUser) + if !ok { + return fmt.Errorf("tastypieApikey cannot load %T as %q", retrieved, name) + } + + o.R.UserAuthUser = rel + + if rel != nil { + rel.R.UserTastypieApikey = o + } + return nil + default: + return fmt.Errorf("tastypieApikey has no relationship %q", name) + } +} + +type tastypieApikeyPreloader struct { + UserAuthUser func(...mysql.PreloadOption) mysql.Preloader +} + +func buildTastypieApikeyPreloader() tastypieApikeyPreloader { + return tastypieApikeyPreloader{ + UserAuthUser: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthUser, AuthUserSlice](mysql.PreloadRel{ + Name: "UserAuthUser", + Sides: []mysql.PreloadSide{ + { + From: TastypieApikeys, + To: AuthUsers, + FromColumns: []string{"user_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthUsers.Columns.Names(), opts...) + }, + } +} + +type tastypieApikeyThenLoader[Q orm.Loadable] struct { + UserAuthUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildTastypieApikeyThenLoader[Q orm.Loadable]() tastypieApikeyThenLoader[Q] { + type UserAuthUserLoadInterface interface { + LoadUserAuthUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return tastypieApikeyThenLoader[Q]{ + UserAuthUser: thenLoadBuilder[Q]( + "UserAuthUser", + func(ctx context.Context, exec bob.Executor, retrieved UserAuthUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUserAuthUser(ctx, exec, mods...) + }, + ), + } +} + +// LoadUserAuthUser loads the tastypieApikey's UserAuthUser into the .R struct +func (o *TastypieApikey) LoadUserAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UserAuthUser = nil + + related, err := o.UserAuthUser(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.UserTastypieApikey = o + + o.R.UserAuthUser = related + return nil +} + +// LoadUserAuthUser loads the tastypieApikey's UserAuthUser into the .R struct +func (os TastypieApikeySlice) LoadUserAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUsers, err := os.UserAuthUser(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUsers { + + if !(o.UserID == rel.ID) { + continue + } + + rel.R.UserTastypieApikey = o + + o.R.UserAuthUser = rel + break + } + } + + return nil +} + +type tastypieApikeyJoins[Q dialect.Joinable] struct { + typ string + UserAuthUser modAs[Q, authUserColumns] +} + +func (j tastypieApikeyJoins[Q]) aliasedAs(alias string) tastypieApikeyJoins[Q] { + return buildTastypieApikeyJoins[Q](buildTastypieApikeyColumns(alias), j.typ) +} + +func buildTastypieApikeyJoins[Q dialect.Joinable](cols tastypieApikeyColumns, typ string) tastypieApikeyJoins[Q] { + return tastypieApikeyJoins[Q]{ + typ: typ, + UserAuthUser: modAs[Q, authUserColumns]{ + c: AuthUsers.Columns, + f: func(to authUserColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUsers.Name().As(to.Alias())).On( + to.ID.EQ(cols.UserID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/dberrors/administration_settings.bob.go b/database/storage_service/dberrors/administration_settings.bob.go new file mode 100644 index 0000000..1d7e2a8 --- /dev/null +++ b/database/storage_service/dberrors/administration_settings.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var AdministrationSettingErrors = &administrationSettingErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "administration_settings", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueName: &UniqueConstraintError{ + schema: "", + table: "administration_settings", + columns: []string{"name"}, + s: "name", + }, +} + +type administrationSettingErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueName *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/auth_group.bob.go b/database/storage_service/dberrors/auth_group.bob.go new file mode 100644 index 0000000..35c596d --- /dev/null +++ b/database/storage_service/dberrors/auth_group.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var AuthGroupErrors = &authGroupErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "auth_group", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueName: &UniqueConstraintError{ + schema: "", + table: "auth_group", + columns: []string{"name"}, + s: "name", + }, +} + +type authGroupErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueName *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/auth_group_permissions.bob.go b/database/storage_service/dberrors/auth_group_permissions.bob.go new file mode 100644 index 0000000..caa7b74 --- /dev/null +++ b/database/storage_service/dberrors/auth_group_permissions.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var AuthGroupPermissionErrors = &authGroupPermissionErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "auth_group_permissions", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueAuthGroupPermissionsGroupIdPermissionId0cd325b0Uniq: &UniqueConstraintError{ + schema: "", + table: "auth_group_permissions", + columns: []string{"group_id", "permission_id"}, + s: "auth_group_permissions_group_id_permission_id_0cd325b0_uniq", + }, +} + +type authGroupPermissionErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueAuthGroupPermissionsGroupIdPermissionId0cd325b0Uniq *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/auth_permission.bob.go b/database/storage_service/dberrors/auth_permission.bob.go new file mode 100644 index 0000000..3cfef8e --- /dev/null +++ b/database/storage_service/dberrors/auth_permission.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var AuthPermissionErrors = &authPermissionErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "auth_permission", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueAuthPermissionContentTypeIdCodename01ab375aUniq: &UniqueConstraintError{ + schema: "", + table: "auth_permission", + columns: []string{"content_type_id", "codename"}, + s: "auth_permission_content_type_id_codename_01ab375a_uniq", + }, +} + +type authPermissionErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueAuthPermissionContentTypeIdCodename01ab375aUniq *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/auth_user.bob.go b/database/storage_service/dberrors/auth_user.bob.go new file mode 100644 index 0000000..b933676 --- /dev/null +++ b/database/storage_service/dberrors/auth_user.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var AuthUserErrors = &authUserErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "auth_user", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUsername: &UniqueConstraintError{ + schema: "", + table: "auth_user", + columns: []string{"username"}, + s: "username", + }, +} + +type authUserErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUsername *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/auth_user_groups.bob.go b/database/storage_service/dberrors/auth_user_groups.bob.go new file mode 100644 index 0000000..4dc8413 --- /dev/null +++ b/database/storage_service/dberrors/auth_user_groups.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var AuthUserGroupErrors = &authUserGroupErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "auth_user_groups", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueAuthUserGroupsUserIdGroupId94350c0cUniq: &UniqueConstraintError{ + schema: "", + table: "auth_user_groups", + columns: []string{"user_id", "group_id"}, + s: "auth_user_groups_user_id_group_id_94350c0c_uniq", + }, +} + +type authUserGroupErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueAuthUserGroupsUserIdGroupId94350c0cUniq *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/auth_user_user_permissions.bob.go b/database/storage_service/dberrors/auth_user_user_permissions.bob.go new file mode 100644 index 0000000..5f55490 --- /dev/null +++ b/database/storage_service/dberrors/auth_user_user_permissions.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var AuthUserUserPermissionErrors = &authUserUserPermissionErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "auth_user_user_permissions", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueAuthUserUserPermissionsUserIdPermissionId14a6b632Uniq: &UniqueConstraintError{ + schema: "", + table: "auth_user_user_permissions", + columns: []string{"user_id", "permission_id"}, + s: "auth_user_user_permissions_user_id_permission_id_14a6b632_uniq", + }, +} + +type authUserUserPermissionErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueAuthUserUserPermissionsUserIdPermissionId14a6b632Uniq *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/bob_errors.bob.go b/database/storage_service/dberrors/bob_errors.bob.go new file mode 100644 index 0000000..3ad7ea4 --- /dev/null +++ b/database/storage_service/dberrors/bob_errors.bob.go @@ -0,0 +1,36 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +import ( + "strings" + + mysqlDriver "github.com/go-sql-driver/mysql" +) + +// ErrUniqueConstraint captures all unique constraint errors by explicitly leaving `s` empty. +var ErrUniqueConstraint = &UniqueConstraintError{s: ""} + +type UniqueConstraintError struct { + // schema is the schema where the unique constraint is defined. + schema string + // table is the name of the table where the unique constraint is defined. + table string + // columns are the columns constituting the unique constraint. + columns []string + // s is a string uniquely identifying the constraint in the raw error message returned from the database. + s string +} + +func (e *UniqueConstraintError) Error() string { + return e.s +} + +func (e *UniqueConstraintError) Is(target error) bool { + err, ok := target.(*mysqlDriver.MySQLError) + if !ok { + return false + } + return err.Number == 1062 && strings.Contains(err.Message, e.s) +} diff --git a/database/storage_service/dberrors/bob_main.bob_test.go b/database/storage_service/dberrors/bob_main.bob_test.go new file mode 100644 index 0000000..886fbd5 --- /dev/null +++ b/database/storage_service/dberrors/bob_main.bob_test.go @@ -0,0 +1,9 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +import "github.com/stephenafamo/bob" + +// Set the testDB to enable tests that use the database +var testDB bob.Transactor[bob.Tx] diff --git a/database/storage_service/dberrors/django_admin_log.bob.go b/database/storage_service/dberrors/django_admin_log.bob.go new file mode 100644 index 0000000..33d7db2 --- /dev/null +++ b/database/storage_service/dberrors/django_admin_log.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var DjangoAdminLogErrors = &djangoAdminLogErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "django_admin_log", + columns: []string{"id"}, + s: "PRIMARY", + }, +} + +type djangoAdminLogErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/django_content_type.bob.go b/database/storage_service/dberrors/django_content_type.bob.go new file mode 100644 index 0000000..12f7270 --- /dev/null +++ b/database/storage_service/dberrors/django_content_type.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var DjangoContentTypeErrors = &djangoContentTypeErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "django_content_type", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueDjangoContentTypeAppLabelModel76bd3d3bUniq: &UniqueConstraintError{ + schema: "", + table: "django_content_type", + columns: []string{"app_label", "model"}, + s: "django_content_type_app_label_model_76bd3d3b_uniq", + }, +} + +type djangoContentTypeErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueDjangoContentTypeAppLabelModel76bd3d3bUniq *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/django_migrations.bob.go b/database/storage_service/dberrors/django_migrations.bob.go new file mode 100644 index 0000000..da2757f --- /dev/null +++ b/database/storage_service/dberrors/django_migrations.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var DjangoMigrationErrors = &djangoMigrationErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "django_migrations", + columns: []string{"id"}, + s: "PRIMARY", + }, +} + +type djangoMigrationErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/django_session.bob.go b/database/storage_service/dberrors/django_session.bob.go new file mode 100644 index 0000000..746a439 --- /dev/null +++ b/database/storage_service/dberrors/django_session.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var DjangoSessionErrors = &djangoSessionErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "django_session", + columns: []string{"session_key"}, + s: "PRIMARY", + }, +} + +type djangoSessionErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/django_site.bob.go b/database/storage_service/dberrors/django_site.bob.go new file mode 100644 index 0000000..a6151db --- /dev/null +++ b/database/storage_service/dberrors/django_site.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var DjangoSiteErrors = &djangoSiteErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "django_site", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueDjangoSiteDomainA2e37b91Uniq: &UniqueConstraintError{ + schema: "", + table: "django_site", + columns: []string{"domain"}, + s: "django_site_domain_a2e37b91_uniq", + }, +} + +type djangoSiteErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueDjangoSiteDomainA2e37b91Uniq *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_archipelago.bob.go b/database/storage_service/dberrors/locations_archipelago.bob.go new file mode 100644 index 0000000..5b74b98 --- /dev/null +++ b/database/storage_service/dberrors/locations_archipelago.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsArchipelagoErrors = &locationsArchipelagoErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_archipelago", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_archipelago", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsArchipelagoErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_arkivum.bob.go b/database/storage_service/dberrors/locations_arkivum.bob.go new file mode 100644 index 0000000..a1b3267 --- /dev/null +++ b/database/storage_service/dberrors/locations_arkivum.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsArkivumErrors = &locationsArkivumErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_arkivum", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_arkivum", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsArkivumErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_async.bob.go b/database/storage_service/dberrors/locations_async.bob.go new file mode 100644 index 0000000..c1690cc --- /dev/null +++ b/database/storage_service/dberrors/locations_async.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsAsyncErrors = &locationsAsyncErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_async", + columns: []string{"id"}, + s: "PRIMARY", + }, +} + +type locationsAsyncErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_callback.bob.go b/database/storage_service/dberrors/locations_callback.bob.go new file mode 100644 index 0000000..2100663 --- /dev/null +++ b/database/storage_service/dberrors/locations_callback.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsCallbackErrors = &locationsCallbackErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_callback", + columns: []string{"id"}, + s: "PRIMARY", + }, +} + +type locationsCallbackErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_dataverse.bob.go b/database/storage_service/dberrors/locations_dataverse.bob.go new file mode 100644 index 0000000..116f8f1 --- /dev/null +++ b/database/storage_service/dberrors/locations_dataverse.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsDataverseErrors = &locationsDataverseErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_dataverse", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_dataverse", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsDataverseErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_dspace.bob.go b/database/storage_service/dberrors/locations_dspace.bob.go new file mode 100644 index 0000000..b72a25c --- /dev/null +++ b/database/storage_service/dberrors/locations_dspace.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsDspaceErrors = &locationsDspaceErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_dspace", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_dspace", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsDspaceErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_dspacerest.bob.go b/database/storage_service/dberrors/locations_dspacerest.bob.go new file mode 100644 index 0000000..39a2cb5 --- /dev/null +++ b/database/storage_service/dberrors/locations_dspacerest.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsDspacerestErrors = &locationsDspacerestErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_dspacerest", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_dspacerest", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsDspacerestErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_duracloud.bob.go b/database/storage_service/dberrors/locations_duracloud.bob.go new file mode 100644 index 0000000..5cd35a4 --- /dev/null +++ b/database/storage_service/dberrors/locations_duracloud.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsDuracloudErrors = &locationsDuracloudErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_duracloud", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_duracloud", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsDuracloudErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_event.bob.go b/database/storage_service/dberrors/locations_event.bob.go new file mode 100644 index 0000000..d79e67a --- /dev/null +++ b/database/storage_service/dberrors/locations_event.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsEventErrors = &locationsEventErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_event", + columns: []string{"id"}, + s: "PRIMARY", + }, +} + +type locationsEventErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_fedora.bob.go b/database/storage_service/dberrors/locations_fedora.bob.go new file mode 100644 index 0000000..d11576f --- /dev/null +++ b/database/storage_service/dberrors/locations_fedora.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsFedoraErrors = &locationsFedoraErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_fedora", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_fedora", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsFedoraErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_file.bob.go b/database/storage_service/dberrors/locations_file.bob.go new file mode 100644 index 0000000..9caf74a --- /dev/null +++ b/database/storage_service/dberrors/locations_file.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsFileErrors = &locationsFileErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_file", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUuid: &UniqueConstraintError{ + schema: "", + table: "locations_file", + columns: []string{"uuid"}, + s: "uuid", + }, +} + +type locationsFileErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUuid *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_fixitylog.bob.go b/database/storage_service/dberrors/locations_fixitylog.bob.go new file mode 100644 index 0000000..bc06555 --- /dev/null +++ b/database/storage_service/dberrors/locations_fixitylog.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsFixitylogErrors = &locationsFixitylogErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_fixitylog", + columns: []string{"id"}, + s: "PRIMARY", + }, +} + +type locationsFixitylogErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_gpg.bob.go b/database/storage_service/dberrors/locations_gpg.bob.go new file mode 100644 index 0000000..cfd0802 --- /dev/null +++ b/database/storage_service/dberrors/locations_gpg.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsGPGErrors = &locationsGPGErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_gpg", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_gpg", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsGPGErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_localfilesystem.bob.go b/database/storage_service/dberrors/locations_localfilesystem.bob.go new file mode 100644 index 0000000..16c8142 --- /dev/null +++ b/database/storage_service/dberrors/locations_localfilesystem.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsLocalfilesystemErrors = &locationsLocalfilesystemErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_localfilesystem", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_localfilesystem", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsLocalfilesystemErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_location.bob.go b/database/storage_service/dberrors/locations_location.bob.go new file mode 100644 index 0000000..8aba8ca --- /dev/null +++ b/database/storage_service/dberrors/locations_location.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsLocationErrors = &locationsLocationErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_location", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUuid: &UniqueConstraintError{ + schema: "", + table: "locations_location", + columns: []string{"uuid"}, + s: "uuid", + }, +} + +type locationsLocationErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUuid *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_location_replicators.bob.go b/database/storage_service/dberrors/locations_location_replicators.bob.go new file mode 100644 index 0000000..e737ec8 --- /dev/null +++ b/database/storage_service/dberrors/locations_location_replicators.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsLocationReplicatorErrors = &locationsLocationReplicatorErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_location_replicators", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueLocationsLocationRepliFromLocationIdToLoca5f763358Uniq: &UniqueConstraintError{ + schema: "", + table: "locations_location_replicators", + columns: []string{"from_location_id", "to_location_id"}, + s: "locations_location_repli_from_location_id_to_loca_5f763358_uniq", + }, +} + +type locationsLocationReplicatorErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueLocationsLocationRepliFromLocationIdToLoca5f763358Uniq *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_locationpipeline.bob.go b/database/storage_service/dberrors/locations_locationpipeline.bob.go new file mode 100644 index 0000000..2257404 --- /dev/null +++ b/database/storage_service/dberrors/locations_locationpipeline.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsLocationpipelineErrors = &locationsLocationpipelineErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_locationpipeline", + columns: []string{"id"}, + s: "PRIMARY", + }, +} + +type locationsLocationpipelineErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_lockssomatic.bob.go b/database/storage_service/dberrors/locations_lockssomatic.bob.go new file mode 100644 index 0000000..87549d6 --- /dev/null +++ b/database/storage_service/dberrors/locations_lockssomatic.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsLockssomaticErrors = &locationsLockssomaticErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_lockssomatic", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_lockssomatic", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsLockssomaticErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_nfs.bob.go b/database/storage_service/dberrors/locations_nfs.bob.go new file mode 100644 index 0000000..d57f7fb --- /dev/null +++ b/database/storage_service/dberrors/locations_nfs.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsNFErrors = &locationsNFErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_nfs", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_nfs", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsNFErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_offlinereplicastaging.bob.go b/database/storage_service/dberrors/locations_offlinereplicastaging.bob.go new file mode 100644 index 0000000..abb7316 --- /dev/null +++ b/database/storage_service/dberrors/locations_offlinereplicastaging.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsOfflinereplicastagingErrors = &locationsOfflinereplicastagingErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_offlinereplicastaging", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_offlinereplicastaging", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsOfflinereplicastagingErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_package.bob.go b/database/storage_service/dberrors/locations_package.bob.go new file mode 100644 index 0000000..d71fb8f --- /dev/null +++ b/database/storage_service/dberrors/locations_package.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsPackageErrors = &locationsPackageErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_package", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUuid: &UniqueConstraintError{ + schema: "", + table: "locations_package", + columns: []string{"uuid"}, + s: "uuid", + }, +} + +type locationsPackageErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUuid *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_package_related_packages.bob.go b/database/storage_service/dberrors/locations_package_related_packages.bob.go new file mode 100644 index 0000000..431d031 --- /dev/null +++ b/database/storage_service/dberrors/locations_package_related_packages.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsPackageRelatedPackageErrors = &locationsPackageRelatedPackageErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_package_related_packages", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueLocationsPackageRelateFromPackageIdToPacka1f820ccfUniq: &UniqueConstraintError{ + schema: "", + table: "locations_package_related_packages", + columns: []string{"from_package_id", "to_package_id"}, + s: "locations_package_relate_from_package_id_to_packa_1f820ccf_uniq", + }, +} + +type locationsPackageRelatedPackageErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueLocationsPackageRelateFromPackageIdToPacka1f820ccfUniq *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_packagedownloadtask.bob.go b/database/storage_service/dberrors/locations_packagedownloadtask.bob.go new file mode 100644 index 0000000..b949169 --- /dev/null +++ b/database/storage_service/dberrors/locations_packagedownloadtask.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsPackagedownloadtaskErrors = &locationsPackagedownloadtaskErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_packagedownloadtask", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUuid: &UniqueConstraintError{ + schema: "", + table: "locations_packagedownloadtask", + columns: []string{"uuid"}, + s: "uuid", + }, +} + +type locationsPackagedownloadtaskErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUuid *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_packagedownloadtaskfile.bob.go b/database/storage_service/dberrors/locations_packagedownloadtaskfile.bob.go new file mode 100644 index 0000000..097eeeb --- /dev/null +++ b/database/storage_service/dberrors/locations_packagedownloadtaskfile.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsPackagedownloadtaskfileErrors = &locationsPackagedownloadtaskfileErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_packagedownloadtaskfile", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUuid: &UniqueConstraintError{ + schema: "", + table: "locations_packagedownloadtaskfile", + columns: []string{"uuid"}, + s: "uuid", + }, +} + +type locationsPackagedownloadtaskfileErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUuid *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_pipeline.bob.go b/database/storage_service/dberrors/locations_pipeline.bob.go new file mode 100644 index 0000000..1baf6d2 --- /dev/null +++ b/database/storage_service/dberrors/locations_pipeline.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsPipelineErrors = &locationsPipelineErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_pipeline", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUuid: &UniqueConstraintError{ + schema: "", + table: "locations_pipeline", + columns: []string{"uuid"}, + s: "uuid", + }, +} + +type locationsPipelineErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUuid *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_pipelinelocalfs.bob.go b/database/storage_service/dberrors/locations_pipelinelocalfs.bob.go new file mode 100644 index 0000000..e0856fa --- /dev/null +++ b/database/storage_service/dberrors/locations_pipelinelocalfs.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsPipelinelocalfErrors = &locationsPipelinelocalfErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_pipelinelocalfs", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_pipelinelocalfs", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsPipelinelocalfErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_rclone.bob.go b/database/storage_service/dberrors/locations_rclone.bob.go new file mode 100644 index 0000000..64dfd2e --- /dev/null +++ b/database/storage_service/dberrors/locations_rclone.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsRcloneErrors = &locationsRcloneErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_rclone", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_rclone", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsRcloneErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_s3.bob.go b/database/storage_service/dberrors/locations_s3.bob.go new file mode 100644 index 0000000..40fd789 --- /dev/null +++ b/database/storage_service/dberrors/locations_s3.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsS3Errors = &locationsS3Errors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_s3", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_s3", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsS3Errors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_space.bob.go b/database/storage_service/dberrors/locations_space.bob.go new file mode 100644 index 0000000..5c4c663 --- /dev/null +++ b/database/storage_service/dberrors/locations_space.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsSpaceErrors = &locationsSpaceErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_space", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUuid: &UniqueConstraintError{ + schema: "", + table: "locations_space", + columns: []string{"uuid"}, + s: "uuid", + }, +} + +type locationsSpaceErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUuid *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/locations_swift.bob.go b/database/storage_service/dberrors/locations_swift.bob.go new file mode 100644 index 0000000..2618cdd --- /dev/null +++ b/database/storage_service/dberrors/locations_swift.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var LocationsSwiftErrors = &locationsSwiftErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "locations_swift", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueSpaceId: &UniqueConstraintError{ + schema: "", + table: "locations_swift", + columns: []string{"space_id"}, + s: "space_id", + }, +} + +type locationsSwiftErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueSpaceId *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/tastypie_apiaccess.bob.go b/database/storage_service/dberrors/tastypie_apiaccess.bob.go new file mode 100644 index 0000000..c13e866 --- /dev/null +++ b/database/storage_service/dberrors/tastypie_apiaccess.bob.go @@ -0,0 +1,17 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var TastypieApiaccessErrors = &tastypieApiaccessErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "tastypie_apiaccess", + columns: []string{"id"}, + s: "PRIMARY", + }, +} + +type tastypieApiaccessErrors struct { + ErrUniquePrimary *UniqueConstraintError +} diff --git a/database/storage_service/dberrors/tastypie_apikey.bob.go b/database/storage_service/dberrors/tastypie_apikey.bob.go new file mode 100644 index 0000000..0368fb9 --- /dev/null +++ b/database/storage_service/dberrors/tastypie_apikey.bob.go @@ -0,0 +1,26 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package dberrors + +var TastypieApikeyErrors = &tastypieApikeyErrors{ + ErrUniquePrimary: &UniqueConstraintError{ + schema: "", + table: "tastypie_apikey", + columns: []string{"id"}, + s: "PRIMARY", + }, + + ErrUniqueUserId: &UniqueConstraintError{ + schema: "", + table: "tastypie_apikey", + columns: []string{"user_id"}, + s: "user_id", + }, +} + +type tastypieApikeyErrors struct { + ErrUniquePrimary *UniqueConstraintError + + ErrUniqueUserId *UniqueConstraintError +} diff --git a/database/storage_service/models/administration_settings.bob.go b/database/storage_service/models/administration_settings.bob.go new file mode 100644 index 0000000..06bed73 --- /dev/null +++ b/database/storage_service/models/administration_settings.bob.go @@ -0,0 +1,396 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" +) + +// AdministrationSetting is an object representing the database table. +type AdministrationSetting struct { + ID int32 `db:"id,pk,autoincr" ` + Name string `db:"name" ` + Value null.Val[string] `db:"value" ` +} + +// AdministrationSettingSlice is an alias for a slice of pointers to AdministrationSetting. +// This should almost always be used instead of []*AdministrationSetting. +type AdministrationSettingSlice []*AdministrationSetting + +// AdministrationSettings contains methods to work with the administration_settings table +var AdministrationSettings = mysql.NewTablex[*AdministrationSetting, AdministrationSettingSlice, *AdministrationSettingSetter]("administration_settings", buildAdministrationSettingColumns("administration_settings"), []string{"id"}, []string{"name"}) + +// AdministrationSettingsQuery is a query on the administration_settings table +type AdministrationSettingsQuery = *mysql.ViewQuery[*AdministrationSetting, AdministrationSettingSlice] + +func buildAdministrationSettingColumns(alias string) administrationSettingColumns { + return administrationSettingColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "name", "value", + ).WithParent("administration_settings"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Name: mysql.Quote(alias, "name"), + Value: mysql.Quote(alias, "value"), + } +} + +type administrationSettingColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Name mysql.Expression + Value mysql.Expression +} + +func (c administrationSettingColumns) Alias() string { + return c.tableAlias +} + +func (administrationSettingColumns) AliasedAs(alias string) administrationSettingColumns { + return buildAdministrationSettingColumns(alias) +} + +// AdministrationSettingSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type AdministrationSettingSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Name omit.Val[string] `db:"name" ` + Value omitnull.Val[string] `db:"value" ` +} + +func (s AdministrationSettingSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Name.IsValue() { + vals = append(vals, "name") + } + if !s.Value.IsUnset() { + vals = append(vals, "value") + } + return vals +} + +func (s AdministrationSettingSetter) Overwrite(t *AdministrationSetting) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Name.IsValue() { + t.Name = s.Name.MustGet() + } + if !s.Value.IsUnset() { + t.Value = s.Value.MustGetNull() + } +} + +func (s *AdministrationSettingSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AdministrationSettings.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Name.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Name.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Value.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Value.MustGetNull()).WriteSQL(ctx, w, d, start) + })) +} + +func (s AdministrationSettingSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("administration_settings")...) +} + +func (s AdministrationSettingSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Name.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "name")...), + mysql.Arg(s.Name), + }}) + } + + if !s.Value.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "value")...), + mysql.Arg(s.Value), + }}) + } + + return exprs +} + +// FindAdministrationSetting retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindAdministrationSetting(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*AdministrationSetting, error) { + if len(cols) == 0 { + return AdministrationSettings.Query( + sm.Where(AdministrationSettings.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return AdministrationSettings.Query( + sm.Where(AdministrationSettings.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(AdministrationSettings.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// AdministrationSettingExists checks the presence of a single record by primary key +func AdministrationSettingExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return AdministrationSettings.Query( + sm.Where(AdministrationSettings.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after AdministrationSetting is retrieved from the database +func (o *AdministrationSetting) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AdministrationSettings.AfterSelectHooks.RunHooks(ctx, exec, AdministrationSettingSlice{o}) + case bob.QueryTypeInsert: + ctx, err = AdministrationSettings.AfterInsertHooks.RunHooks(ctx, exec, AdministrationSettingSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = AdministrationSettings.AfterUpdateHooks.RunHooks(ctx, exec, AdministrationSettingSlice{o}) + case bob.QueryTypeDelete: + ctx, err = AdministrationSettings.AfterDeleteHooks.RunHooks(ctx, exec, AdministrationSettingSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the AdministrationSetting +func (o *AdministrationSetting) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *AdministrationSetting) pkEQ() dialect.Expression { + return mysql.Quote("administration_settings", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the AdministrationSetting +func (o *AdministrationSetting) Update(ctx context.Context, exec bob.Executor, s *AdministrationSettingSetter) error { + _, err := AdministrationSettings.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single AdministrationSetting record with an executor +func (o *AdministrationSetting) Delete(ctx context.Context, exec bob.Executor) error { + _, err := AdministrationSettings.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the AdministrationSetting using the executor +func (o *AdministrationSetting) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := AdministrationSettings.Query( + sm.Where(AdministrationSettings.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + + *o = *o2 + + return nil +} + +// AfterQueryHook is called after AdministrationSettingSlice is retrieved from the database +func (o AdministrationSettingSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AdministrationSettings.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = AdministrationSettings.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = AdministrationSettings.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = AdministrationSettings.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o AdministrationSettingSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("administration_settings", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o AdministrationSettingSlice) copyMatchingRows(from ...*AdministrationSetting) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o AdministrationSettingSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AdministrationSettings.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AdministrationSetting: + o.copyMatchingRows(retrieved) + case []*AdministrationSetting: + o.copyMatchingRows(retrieved...) + case AdministrationSettingSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AdministrationSetting or a slice of AdministrationSetting + // then run the AfterUpdateHooks on the slice + _, err = AdministrationSettings.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o AdministrationSettingSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AdministrationSettings.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AdministrationSetting: + o.copyMatchingRows(retrieved) + case []*AdministrationSetting: + o.copyMatchingRows(retrieved...) + case AdministrationSettingSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AdministrationSetting or a slice of AdministrationSetting + // then run the AfterDeleteHooks on the slice + _, err = AdministrationSettings.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o AdministrationSettingSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals AdministrationSettingSetter) error { + _, err := AdministrationSettings.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o AdministrationSettingSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := AdministrationSettings.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o AdministrationSettingSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := AdministrationSettings.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +type administrationSettingWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Name mysql.WhereMod[Q, string] + Value mysql.WhereNullMod[Q, string] +} + +func (administrationSettingWhere[Q]) AliasedAs(alias string) administrationSettingWhere[Q] { + return buildAdministrationSettingWhere[Q](buildAdministrationSettingColumns(alias)) +} + +func buildAdministrationSettingWhere[Q mysql.Filterable](cols administrationSettingColumns) administrationSettingWhere[Q] { + return administrationSettingWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Name: mysql.Where[Q, string](cols.Name), + Value: mysql.WhereNull[Q, string](cols.Value), + } +} diff --git a/database/storage_service/models/auth_group.bob.go b/database/storage_service/models/auth_group.bob.go new file mode 100644 index 0000000..3143b0f --- /dev/null +++ b/database/storage_service/models/auth_group.bob.go @@ -0,0 +1,795 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// AuthGroup is an object representing the database table. +type AuthGroup struct { + ID int32 `db:"id,pk,autoincr" ` + Name string `db:"name" ` + + R authGroupR `db:"-" ` +} + +// AuthGroupSlice is an alias for a slice of pointers to AuthGroup. +// This should almost always be used instead of []*AuthGroup. +type AuthGroupSlice []*AuthGroup + +// AuthGroups contains methods to work with the auth_group table +var AuthGroups = mysql.NewTablex[*AuthGroup, AuthGroupSlice, *AuthGroupSetter]("auth_group", buildAuthGroupColumns("auth_group"), []string{"id"}, []string{"name"}) + +// AuthGroupsQuery is a query on the auth_group table +type AuthGroupsQuery = *mysql.ViewQuery[*AuthGroup, AuthGroupSlice] + +// authGroupR is where relationships are stored. +type authGroupR struct { + GroupAuthGroupPermissions AuthGroupPermissionSlice // auth_group_permissions_group_id_b120cbf9_fk_auth_group_id + GroupAuthUserGroups AuthUserGroupSlice // auth_user_groups_group_id_97559544_fk_auth_group_id +} + +func buildAuthGroupColumns(alias string) authGroupColumns { + return authGroupColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "name", + ).WithParent("auth_group"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Name: mysql.Quote(alias, "name"), + } +} + +type authGroupColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Name mysql.Expression +} + +func (c authGroupColumns) Alias() string { + return c.tableAlias +} + +func (authGroupColumns) AliasedAs(alias string) authGroupColumns { + return buildAuthGroupColumns(alias) +} + +// AuthGroupSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type AuthGroupSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Name omit.Val[string] `db:"name" ` +} + +func (s AuthGroupSetter) SetColumns() []string { + vals := make([]string, 0, 2) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Name.IsValue() { + vals = append(vals, "name") + } + return vals +} + +func (s AuthGroupSetter) Overwrite(t *AuthGroup) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Name.IsValue() { + t.Name = s.Name.MustGet() + } +} + +func (s *AuthGroupSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthGroups.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Name.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Name.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s AuthGroupSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("auth_group")...) +} + +func (s AuthGroupSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 2) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Name.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "name")...), + mysql.Arg(s.Name), + }}) + } + + return exprs +} + +// FindAuthGroup retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindAuthGroup(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*AuthGroup, error) { + if len(cols) == 0 { + return AuthGroups.Query( + sm.Where(AuthGroups.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return AuthGroups.Query( + sm.Where(AuthGroups.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(AuthGroups.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// AuthGroupExists checks the presence of a single record by primary key +func AuthGroupExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return AuthGroups.Query( + sm.Where(AuthGroups.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after AuthGroup is retrieved from the database +func (o *AuthGroup) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthGroups.AfterSelectHooks.RunHooks(ctx, exec, AuthGroupSlice{o}) + case bob.QueryTypeInsert: + ctx, err = AuthGroups.AfterInsertHooks.RunHooks(ctx, exec, AuthGroupSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = AuthGroups.AfterUpdateHooks.RunHooks(ctx, exec, AuthGroupSlice{o}) + case bob.QueryTypeDelete: + ctx, err = AuthGroups.AfterDeleteHooks.RunHooks(ctx, exec, AuthGroupSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the AuthGroup +func (o *AuthGroup) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *AuthGroup) pkEQ() dialect.Expression { + return mysql.Quote("auth_group", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the AuthGroup +func (o *AuthGroup) Update(ctx context.Context, exec bob.Executor, s *AuthGroupSetter) error { + _, err := AuthGroups.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single AuthGroup record with an executor +func (o *AuthGroup) Delete(ctx context.Context, exec bob.Executor) error { + _, err := AuthGroups.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the AuthGroup using the executor +func (o *AuthGroup) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := AuthGroups.Query( + sm.Where(AuthGroups.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after AuthGroupSlice is retrieved from the database +func (o AuthGroupSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthGroups.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = AuthGroups.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = AuthGroups.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = AuthGroups.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o AuthGroupSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("auth_group", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o AuthGroupSlice) copyMatchingRows(from ...*AuthGroup) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o AuthGroupSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthGroups.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthGroup: + o.copyMatchingRows(retrieved) + case []*AuthGroup: + o.copyMatchingRows(retrieved...) + case AuthGroupSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthGroup or a slice of AuthGroup + // then run the AfterUpdateHooks on the slice + _, err = AuthGroups.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o AuthGroupSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthGroups.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthGroup: + o.copyMatchingRows(retrieved) + case []*AuthGroup: + o.copyMatchingRows(retrieved...) + case AuthGroupSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthGroup or a slice of AuthGroup + // then run the AfterDeleteHooks on the slice + _, err = AuthGroups.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o AuthGroupSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals AuthGroupSetter) error { + _, err := AuthGroups.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o AuthGroupSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := AuthGroups.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o AuthGroupSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := AuthGroups.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// GroupAuthGroupPermissions starts a query for related objects on auth_group_permissions +func (o *AuthGroup) GroupAuthGroupPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthGroupPermissionsQuery { + return AuthGroupPermissions.Query(append(mods, + sm.Where(AuthGroupPermissions.Columns.GroupID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthGroupSlice) GroupAuthGroupPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthGroupPermissionsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthGroupPermissions.Query(append(mods, + sm.Where(mysql.Group(AuthGroupPermissions.Columns.GroupID).OP("IN", PKArgExpr)), + )...) +} + +// GroupAuthUserGroups starts a query for related objects on auth_user_groups +func (o *AuthGroup) GroupAuthUserGroups(mods ...bob.Mod[*dialect.SelectQuery]) AuthUserGroupsQuery { + return AuthUserGroups.Query(append(mods, + sm.Where(AuthUserGroups.Columns.GroupID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthGroupSlice) GroupAuthUserGroups(mods ...bob.Mod[*dialect.SelectQuery]) AuthUserGroupsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUserGroups.Query(append(mods, + sm.Where(mysql.Group(AuthUserGroups.Columns.GroupID).OP("IN", PKArgExpr)), + )...) +} + +func insertAuthGroupGroupAuthGroupPermissions0(ctx context.Context, exec bob.Executor, authGroupPermissions1 []*AuthGroupPermissionSetter, authGroup0 *AuthGroup) (AuthGroupPermissionSlice, error) { + for i := range authGroupPermissions1 { + authGroupPermissions1[i].GroupID = omit.From(authGroup0.ID) + } + + ret, err := AuthGroupPermissions.Insert(bob.ToMods(authGroupPermissions1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthGroupGroupAuthGroupPermissions0: %w", err) + } + + return ret, nil +} + +func attachAuthGroupGroupAuthGroupPermissions0(ctx context.Context, exec bob.Executor, count int, authGroupPermissions1 AuthGroupPermissionSlice, authGroup0 *AuthGroup) (AuthGroupPermissionSlice, error) { + setter := &AuthGroupPermissionSetter{ + GroupID: omit.From(authGroup0.ID), + } + + err := authGroupPermissions1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAuthGroupGroupAuthGroupPermissions0: %w", err) + } + + return authGroupPermissions1, nil +} + +func (authGroup0 *AuthGroup) InsertGroupAuthGroupPermissions(ctx context.Context, exec bob.Executor, related ...*AuthGroupPermissionSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + authGroupPermissions1, err := insertAuthGroupGroupAuthGroupPermissions0(ctx, exec, related, authGroup0) + if err != nil { + return err + } + + authGroup0.R.GroupAuthGroupPermissions = append(authGroup0.R.GroupAuthGroupPermissions, authGroupPermissions1...) + + for _, rel := range authGroupPermissions1 { + rel.R.GroupAuthGroup = authGroup0 + } + return nil +} + +func (authGroup0 *AuthGroup) AttachGroupAuthGroupPermissions(ctx context.Context, exec bob.Executor, related ...*AuthGroupPermission) error { + if len(related) == 0 { + return nil + } + + var err error + authGroupPermissions1 := AuthGroupPermissionSlice(related) + + _, err = attachAuthGroupGroupAuthGroupPermissions0(ctx, exec, len(related), authGroupPermissions1, authGroup0) + if err != nil { + return err + } + + authGroup0.R.GroupAuthGroupPermissions = append(authGroup0.R.GroupAuthGroupPermissions, authGroupPermissions1...) + + for _, rel := range related { + rel.R.GroupAuthGroup = authGroup0 + } + + return nil +} + +func insertAuthGroupGroupAuthUserGroups0(ctx context.Context, exec bob.Executor, authUserGroups1 []*AuthUserGroupSetter, authGroup0 *AuthGroup) (AuthUserGroupSlice, error) { + for i := range authUserGroups1 { + authUserGroups1[i].GroupID = omit.From(authGroup0.ID) + } + + ret, err := AuthUserGroups.Insert(bob.ToMods(authUserGroups1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthGroupGroupAuthUserGroups0: %w", err) + } + + return ret, nil +} + +func attachAuthGroupGroupAuthUserGroups0(ctx context.Context, exec bob.Executor, count int, authUserGroups1 AuthUserGroupSlice, authGroup0 *AuthGroup) (AuthUserGroupSlice, error) { + setter := &AuthUserGroupSetter{ + GroupID: omit.From(authGroup0.ID), + } + + err := authUserGroups1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAuthGroupGroupAuthUserGroups0: %w", err) + } + + return authUserGroups1, nil +} + +func (authGroup0 *AuthGroup) InsertGroupAuthUserGroups(ctx context.Context, exec bob.Executor, related ...*AuthUserGroupSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + authUserGroups1, err := insertAuthGroupGroupAuthUserGroups0(ctx, exec, related, authGroup0) + if err != nil { + return err + } + + authGroup0.R.GroupAuthUserGroups = append(authGroup0.R.GroupAuthUserGroups, authUserGroups1...) + + for _, rel := range authUserGroups1 { + rel.R.GroupAuthGroup = authGroup0 + } + return nil +} + +func (authGroup0 *AuthGroup) AttachGroupAuthUserGroups(ctx context.Context, exec bob.Executor, related ...*AuthUserGroup) error { + if len(related) == 0 { + return nil + } + + var err error + authUserGroups1 := AuthUserGroupSlice(related) + + _, err = attachAuthGroupGroupAuthUserGroups0(ctx, exec, len(related), authUserGroups1, authGroup0) + if err != nil { + return err + } + + authGroup0.R.GroupAuthUserGroups = append(authGroup0.R.GroupAuthUserGroups, authUserGroups1...) + + for _, rel := range related { + rel.R.GroupAuthGroup = authGroup0 + } + + return nil +} + +type authGroupWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Name mysql.WhereMod[Q, string] +} + +func (authGroupWhere[Q]) AliasedAs(alias string) authGroupWhere[Q] { + return buildAuthGroupWhere[Q](buildAuthGroupColumns(alias)) +} + +func buildAuthGroupWhere[Q mysql.Filterable](cols authGroupColumns) authGroupWhere[Q] { + return authGroupWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Name: mysql.Where[Q, string](cols.Name), + } +} + +func (o *AuthGroup) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "GroupAuthGroupPermissions": + rels, ok := retrieved.(AuthGroupPermissionSlice) + if !ok { + return fmt.Errorf("authGroup cannot load %T as %q", retrieved, name) + } + + o.R.GroupAuthGroupPermissions = rels + + for _, rel := range rels { + if rel != nil { + rel.R.GroupAuthGroup = o + } + } + return nil + case "GroupAuthUserGroups": + rels, ok := retrieved.(AuthUserGroupSlice) + if !ok { + return fmt.Errorf("authGroup cannot load %T as %q", retrieved, name) + } + + o.R.GroupAuthUserGroups = rels + + for _, rel := range rels { + if rel != nil { + rel.R.GroupAuthGroup = o + } + } + return nil + default: + return fmt.Errorf("authGroup has no relationship %q", name) + } +} + +type authGroupPreloader struct{} + +func buildAuthGroupPreloader() authGroupPreloader { + return authGroupPreloader{} +} + +type authGroupThenLoader[Q orm.Loadable] struct { + GroupAuthGroupPermissions func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + GroupAuthUserGroups func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildAuthGroupThenLoader[Q orm.Loadable]() authGroupThenLoader[Q] { + type GroupAuthGroupPermissionsLoadInterface interface { + LoadGroupAuthGroupPermissions(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type GroupAuthUserGroupsLoadInterface interface { + LoadGroupAuthUserGroups(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return authGroupThenLoader[Q]{ + GroupAuthGroupPermissions: thenLoadBuilder[Q]( + "GroupAuthGroupPermissions", + func(ctx context.Context, exec bob.Executor, retrieved GroupAuthGroupPermissionsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadGroupAuthGroupPermissions(ctx, exec, mods...) + }, + ), + GroupAuthUserGroups: thenLoadBuilder[Q]( + "GroupAuthUserGroups", + func(ctx context.Context, exec bob.Executor, retrieved GroupAuthUserGroupsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadGroupAuthUserGroups(ctx, exec, mods...) + }, + ), + } +} + +// LoadGroupAuthGroupPermissions loads the authGroup's GroupAuthGroupPermissions into the .R struct +func (o *AuthGroup) LoadGroupAuthGroupPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.GroupAuthGroupPermissions = nil + + related, err := o.GroupAuthGroupPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.GroupAuthGroup = o + } + + o.R.GroupAuthGroupPermissions = related + return nil +} + +// LoadGroupAuthGroupPermissions loads the authGroup's GroupAuthGroupPermissions into the .R struct +func (os AuthGroupSlice) LoadGroupAuthGroupPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authGroupPermissions, err := os.GroupAuthGroupPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.GroupAuthGroupPermissions = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authGroupPermissions { + + if !(o.ID == rel.GroupID) { + continue + } + + rel.R.GroupAuthGroup = o + + o.R.GroupAuthGroupPermissions = append(o.R.GroupAuthGroupPermissions, rel) + } + } + + return nil +} + +// LoadGroupAuthUserGroups loads the authGroup's GroupAuthUserGroups into the .R struct +func (o *AuthGroup) LoadGroupAuthUserGroups(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.GroupAuthUserGroups = nil + + related, err := o.GroupAuthUserGroups(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.GroupAuthGroup = o + } + + o.R.GroupAuthUserGroups = related + return nil +} + +// LoadGroupAuthUserGroups loads the authGroup's GroupAuthUserGroups into the .R struct +func (os AuthGroupSlice) LoadGroupAuthUserGroups(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUserGroups, err := os.GroupAuthUserGroups(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.GroupAuthUserGroups = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUserGroups { + + if !(o.ID == rel.GroupID) { + continue + } + + rel.R.GroupAuthGroup = o + + o.R.GroupAuthUserGroups = append(o.R.GroupAuthUserGroups, rel) + } + } + + return nil +} + +type authGroupJoins[Q dialect.Joinable] struct { + typ string + GroupAuthGroupPermissions modAs[Q, authGroupPermissionColumns] + GroupAuthUserGroups modAs[Q, authUserGroupColumns] +} + +func (j authGroupJoins[Q]) aliasedAs(alias string) authGroupJoins[Q] { + return buildAuthGroupJoins[Q](buildAuthGroupColumns(alias), j.typ) +} + +func buildAuthGroupJoins[Q dialect.Joinable](cols authGroupColumns, typ string) authGroupJoins[Q] { + return authGroupJoins[Q]{ + typ: typ, + GroupAuthGroupPermissions: modAs[Q, authGroupPermissionColumns]{ + c: AuthGroupPermissions.Columns, + f: func(to authGroupPermissionColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthGroupPermissions.Name().As(to.Alias())).On( + to.GroupID.EQ(cols.ID), + )) + } + + return mods + }, + }, + GroupAuthUserGroups: modAs[Q, authUserGroupColumns]{ + c: AuthUserGroups.Columns, + f: func(to authUserGroupColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUserGroups.Name().As(to.Alias())).On( + to.GroupID.EQ(cols.ID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/auth_group_permissions.bob.go b/database/storage_service/models/auth_group_permissions.bob.go new file mode 100644 index 0000000..7e671b0 --- /dev/null +++ b/database/storage_service/models/auth_group_permissions.bob.go @@ -0,0 +1,787 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// AuthGroupPermission is an object representing the database table. +type AuthGroupPermission struct { + ID int32 `db:"id,pk,autoincr" ` + GroupID int32 `db:"group_id" ` + PermissionID int32 `db:"permission_id" ` + + R authGroupPermissionR `db:"-" ` +} + +// AuthGroupPermissionSlice is an alias for a slice of pointers to AuthGroupPermission. +// This should almost always be used instead of []*AuthGroupPermission. +type AuthGroupPermissionSlice []*AuthGroupPermission + +// AuthGroupPermissions contains methods to work with the auth_group_permissions table +var AuthGroupPermissions = mysql.NewTablex[*AuthGroupPermission, AuthGroupPermissionSlice, *AuthGroupPermissionSetter]("auth_group_permissions", buildAuthGroupPermissionColumns("auth_group_permissions"), []string{"id"}, []string{"group_id", "permission_id"}) + +// AuthGroupPermissionsQuery is a query on the auth_group_permissions table +type AuthGroupPermissionsQuery = *mysql.ViewQuery[*AuthGroupPermission, AuthGroupPermissionSlice] + +// authGroupPermissionR is where relationships are stored. +type authGroupPermissionR struct { + PermissionAuthPermission *AuthPermission // auth_group_permissio_permission_id_84c5c92e_fk_auth_perm + GroupAuthGroup *AuthGroup // auth_group_permissions_group_id_b120cbf9_fk_auth_group_id +} + +func buildAuthGroupPermissionColumns(alias string) authGroupPermissionColumns { + return authGroupPermissionColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "group_id", "permission_id", + ).WithParent("auth_group_permissions"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + GroupID: mysql.Quote(alias, "group_id"), + PermissionID: mysql.Quote(alias, "permission_id"), + } +} + +type authGroupPermissionColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + GroupID mysql.Expression + PermissionID mysql.Expression +} + +func (c authGroupPermissionColumns) Alias() string { + return c.tableAlias +} + +func (authGroupPermissionColumns) AliasedAs(alias string) authGroupPermissionColumns { + return buildAuthGroupPermissionColumns(alias) +} + +// AuthGroupPermissionSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type AuthGroupPermissionSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + GroupID omit.Val[int32] `db:"group_id" ` + PermissionID omit.Val[int32] `db:"permission_id" ` +} + +func (s AuthGroupPermissionSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.GroupID.IsValue() { + vals = append(vals, "group_id") + } + if s.PermissionID.IsValue() { + vals = append(vals, "permission_id") + } + return vals +} + +func (s AuthGroupPermissionSetter) Overwrite(t *AuthGroupPermission) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.GroupID.IsValue() { + t.GroupID = s.GroupID.MustGet() + } + if s.PermissionID.IsValue() { + t.PermissionID = s.PermissionID.MustGet() + } +} + +func (s *AuthGroupPermissionSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthGroupPermissions.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.GroupID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.GroupID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.PermissionID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PermissionID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s AuthGroupPermissionSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("auth_group_permissions")...) +} + +func (s AuthGroupPermissionSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.GroupID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "group_id")...), + mysql.Arg(s.GroupID), + }}) + } + + if s.PermissionID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "permission_id")...), + mysql.Arg(s.PermissionID), + }}) + } + + return exprs +} + +// FindAuthGroupPermission retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindAuthGroupPermission(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*AuthGroupPermission, error) { + if len(cols) == 0 { + return AuthGroupPermissions.Query( + sm.Where(AuthGroupPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return AuthGroupPermissions.Query( + sm.Where(AuthGroupPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(AuthGroupPermissions.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// AuthGroupPermissionExists checks the presence of a single record by primary key +func AuthGroupPermissionExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return AuthGroupPermissions.Query( + sm.Where(AuthGroupPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after AuthGroupPermission is retrieved from the database +func (o *AuthGroupPermission) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthGroupPermissions.AfterSelectHooks.RunHooks(ctx, exec, AuthGroupPermissionSlice{o}) + case bob.QueryTypeInsert: + ctx, err = AuthGroupPermissions.AfterInsertHooks.RunHooks(ctx, exec, AuthGroupPermissionSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = AuthGroupPermissions.AfterUpdateHooks.RunHooks(ctx, exec, AuthGroupPermissionSlice{o}) + case bob.QueryTypeDelete: + ctx, err = AuthGroupPermissions.AfterDeleteHooks.RunHooks(ctx, exec, AuthGroupPermissionSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the AuthGroupPermission +func (o *AuthGroupPermission) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *AuthGroupPermission) pkEQ() dialect.Expression { + return mysql.Quote("auth_group_permissions", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the AuthGroupPermission +func (o *AuthGroupPermission) Update(ctx context.Context, exec bob.Executor, s *AuthGroupPermissionSetter) error { + _, err := AuthGroupPermissions.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single AuthGroupPermission record with an executor +func (o *AuthGroupPermission) Delete(ctx context.Context, exec bob.Executor) error { + _, err := AuthGroupPermissions.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the AuthGroupPermission using the executor +func (o *AuthGroupPermission) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := AuthGroupPermissions.Query( + sm.Where(AuthGroupPermissions.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after AuthGroupPermissionSlice is retrieved from the database +func (o AuthGroupPermissionSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthGroupPermissions.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = AuthGroupPermissions.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = AuthGroupPermissions.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = AuthGroupPermissions.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o AuthGroupPermissionSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("auth_group_permissions", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o AuthGroupPermissionSlice) copyMatchingRows(from ...*AuthGroupPermission) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o AuthGroupPermissionSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthGroupPermissions.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthGroupPermission: + o.copyMatchingRows(retrieved) + case []*AuthGroupPermission: + o.copyMatchingRows(retrieved...) + case AuthGroupPermissionSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthGroupPermission or a slice of AuthGroupPermission + // then run the AfterUpdateHooks on the slice + _, err = AuthGroupPermissions.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o AuthGroupPermissionSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthGroupPermissions.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthGroupPermission: + o.copyMatchingRows(retrieved) + case []*AuthGroupPermission: + o.copyMatchingRows(retrieved...) + case AuthGroupPermissionSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthGroupPermission or a slice of AuthGroupPermission + // then run the AfterDeleteHooks on the slice + _, err = AuthGroupPermissions.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o AuthGroupPermissionSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals AuthGroupPermissionSetter) error { + _, err := AuthGroupPermissions.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o AuthGroupPermissionSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := AuthGroupPermissions.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o AuthGroupPermissionSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := AuthGroupPermissions.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// PermissionAuthPermission starts a query for related objects on auth_permission +func (o *AuthGroupPermission) PermissionAuthPermission(mods ...bob.Mod[*dialect.SelectQuery]) AuthPermissionsQuery { + return AuthPermissions.Query(append(mods, + sm.Where(AuthPermissions.Columns.ID.EQ(mysql.Arg(o.PermissionID))), + )...) +} + +func (os AuthGroupPermissionSlice) PermissionAuthPermission(mods ...bob.Mod[*dialect.SelectQuery]) AuthPermissionsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PermissionID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthPermissions.Query(append(mods, + sm.Where(mysql.Group(AuthPermissions.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// GroupAuthGroup starts a query for related objects on auth_group +func (o *AuthGroupPermission) GroupAuthGroup(mods ...bob.Mod[*dialect.SelectQuery]) AuthGroupsQuery { + return AuthGroups.Query(append(mods, + sm.Where(AuthGroups.Columns.ID.EQ(mysql.Arg(o.GroupID))), + )...) +} + +func (os AuthGroupPermissionSlice) GroupAuthGroup(mods ...bob.Mod[*dialect.SelectQuery]) AuthGroupsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.GroupID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthGroups.Query(append(mods, + sm.Where(mysql.Group(AuthGroups.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func attachAuthGroupPermissionPermissionAuthPermission0(ctx context.Context, exec bob.Executor, count int, authGroupPermission0 *AuthGroupPermission, authPermission1 *AuthPermission) (*AuthGroupPermission, error) { + setter := &AuthGroupPermissionSetter{ + PermissionID: omit.From(authPermission1.ID), + } + + err := authGroupPermission0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachAuthGroupPermissionPermissionAuthPermission0: %w", err) + } + + return authGroupPermission0, nil +} + +func (authGroupPermission0 *AuthGroupPermission) InsertPermissionAuthPermission(ctx context.Context, exec bob.Executor, related *AuthPermissionSetter) error { + var err error + + authPermission1, err := AuthPermissions.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachAuthGroupPermissionPermissionAuthPermission0(ctx, exec, 1, authGroupPermission0, authPermission1) + if err != nil { + return err + } + + authGroupPermission0.R.PermissionAuthPermission = authPermission1 + + authPermission1.R.PermissionAuthGroupPermissions = append(authPermission1.R.PermissionAuthGroupPermissions, authGroupPermission0) + + return nil +} + +func (authGroupPermission0 *AuthGroupPermission) AttachPermissionAuthPermission(ctx context.Context, exec bob.Executor, authPermission1 *AuthPermission) error { + var err error + + _, err = attachAuthGroupPermissionPermissionAuthPermission0(ctx, exec, 1, authGroupPermission0, authPermission1) + if err != nil { + return err + } + + authGroupPermission0.R.PermissionAuthPermission = authPermission1 + + authPermission1.R.PermissionAuthGroupPermissions = append(authPermission1.R.PermissionAuthGroupPermissions, authGroupPermission0) + + return nil +} + +func attachAuthGroupPermissionGroupAuthGroup0(ctx context.Context, exec bob.Executor, count int, authGroupPermission0 *AuthGroupPermission, authGroup1 *AuthGroup) (*AuthGroupPermission, error) { + setter := &AuthGroupPermissionSetter{ + GroupID: omit.From(authGroup1.ID), + } + + err := authGroupPermission0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachAuthGroupPermissionGroupAuthGroup0: %w", err) + } + + return authGroupPermission0, nil +} + +func (authGroupPermission0 *AuthGroupPermission) InsertGroupAuthGroup(ctx context.Context, exec bob.Executor, related *AuthGroupSetter) error { + var err error + + authGroup1, err := AuthGroups.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachAuthGroupPermissionGroupAuthGroup0(ctx, exec, 1, authGroupPermission0, authGroup1) + if err != nil { + return err + } + + authGroupPermission0.R.GroupAuthGroup = authGroup1 + + authGroup1.R.GroupAuthGroupPermissions = append(authGroup1.R.GroupAuthGroupPermissions, authGroupPermission0) + + return nil +} + +func (authGroupPermission0 *AuthGroupPermission) AttachGroupAuthGroup(ctx context.Context, exec bob.Executor, authGroup1 *AuthGroup) error { + var err error + + _, err = attachAuthGroupPermissionGroupAuthGroup0(ctx, exec, 1, authGroupPermission0, authGroup1) + if err != nil { + return err + } + + authGroupPermission0.R.GroupAuthGroup = authGroup1 + + authGroup1.R.GroupAuthGroupPermissions = append(authGroup1.R.GroupAuthGroupPermissions, authGroupPermission0) + + return nil +} + +type authGroupPermissionWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + GroupID mysql.WhereMod[Q, int32] + PermissionID mysql.WhereMod[Q, int32] +} + +func (authGroupPermissionWhere[Q]) AliasedAs(alias string) authGroupPermissionWhere[Q] { + return buildAuthGroupPermissionWhere[Q](buildAuthGroupPermissionColumns(alias)) +} + +func buildAuthGroupPermissionWhere[Q mysql.Filterable](cols authGroupPermissionColumns) authGroupPermissionWhere[Q] { + return authGroupPermissionWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + GroupID: mysql.Where[Q, int32](cols.GroupID), + PermissionID: mysql.Where[Q, int32](cols.PermissionID), + } +} + +func (o *AuthGroupPermission) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "PermissionAuthPermission": + rel, ok := retrieved.(*AuthPermission) + if !ok { + return fmt.Errorf("authGroupPermission cannot load %T as %q", retrieved, name) + } + + o.R.PermissionAuthPermission = rel + + if rel != nil { + rel.R.PermissionAuthGroupPermissions = AuthGroupPermissionSlice{o} + } + return nil + case "GroupAuthGroup": + rel, ok := retrieved.(*AuthGroup) + if !ok { + return fmt.Errorf("authGroupPermission cannot load %T as %q", retrieved, name) + } + + o.R.GroupAuthGroup = rel + + if rel != nil { + rel.R.GroupAuthGroupPermissions = AuthGroupPermissionSlice{o} + } + return nil + default: + return fmt.Errorf("authGroupPermission has no relationship %q", name) + } +} + +type authGroupPermissionPreloader struct { + PermissionAuthPermission func(...mysql.PreloadOption) mysql.Preloader + GroupAuthGroup func(...mysql.PreloadOption) mysql.Preloader +} + +func buildAuthGroupPermissionPreloader() authGroupPermissionPreloader { + return authGroupPermissionPreloader{ + PermissionAuthPermission: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthPermission, AuthPermissionSlice](mysql.PreloadRel{ + Name: "PermissionAuthPermission", + Sides: []mysql.PreloadSide{ + { + From: AuthGroupPermissions, + To: AuthPermissions, + FromColumns: []string{"permission_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthPermissions.Columns.Names(), opts...) + }, + GroupAuthGroup: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthGroup, AuthGroupSlice](mysql.PreloadRel{ + Name: "GroupAuthGroup", + Sides: []mysql.PreloadSide{ + { + From: AuthGroupPermissions, + To: AuthGroups, + FromColumns: []string{"group_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthGroups.Columns.Names(), opts...) + }, + } +} + +type authGroupPermissionThenLoader[Q orm.Loadable] struct { + PermissionAuthPermission func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + GroupAuthGroup func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildAuthGroupPermissionThenLoader[Q orm.Loadable]() authGroupPermissionThenLoader[Q] { + type PermissionAuthPermissionLoadInterface interface { + LoadPermissionAuthPermission(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type GroupAuthGroupLoadInterface interface { + LoadGroupAuthGroup(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return authGroupPermissionThenLoader[Q]{ + PermissionAuthPermission: thenLoadBuilder[Q]( + "PermissionAuthPermission", + func(ctx context.Context, exec bob.Executor, retrieved PermissionAuthPermissionLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPermissionAuthPermission(ctx, exec, mods...) + }, + ), + GroupAuthGroup: thenLoadBuilder[Q]( + "GroupAuthGroup", + func(ctx context.Context, exec bob.Executor, retrieved GroupAuthGroupLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadGroupAuthGroup(ctx, exec, mods...) + }, + ), + } +} + +// LoadPermissionAuthPermission loads the authGroupPermission's PermissionAuthPermission into the .R struct +func (o *AuthGroupPermission) LoadPermissionAuthPermission(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PermissionAuthPermission = nil + + related, err := o.PermissionAuthPermission(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PermissionAuthGroupPermissions = AuthGroupPermissionSlice{o} + + o.R.PermissionAuthPermission = related + return nil +} + +// LoadPermissionAuthPermission loads the authGroupPermission's PermissionAuthPermission into the .R struct +func (os AuthGroupPermissionSlice) LoadPermissionAuthPermission(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authPermissions, err := os.PermissionAuthPermission(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authPermissions { + + if !(o.PermissionID == rel.ID) { + continue + } + + rel.R.PermissionAuthGroupPermissions = append(rel.R.PermissionAuthGroupPermissions, o) + + o.R.PermissionAuthPermission = rel + break + } + } + + return nil +} + +// LoadGroupAuthGroup loads the authGroupPermission's GroupAuthGroup into the .R struct +func (o *AuthGroupPermission) LoadGroupAuthGroup(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.GroupAuthGroup = nil + + related, err := o.GroupAuthGroup(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.GroupAuthGroupPermissions = AuthGroupPermissionSlice{o} + + o.R.GroupAuthGroup = related + return nil +} + +// LoadGroupAuthGroup loads the authGroupPermission's GroupAuthGroup into the .R struct +func (os AuthGroupPermissionSlice) LoadGroupAuthGroup(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authGroups, err := os.GroupAuthGroup(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authGroups { + + if !(o.GroupID == rel.ID) { + continue + } + + rel.R.GroupAuthGroupPermissions = append(rel.R.GroupAuthGroupPermissions, o) + + o.R.GroupAuthGroup = rel + break + } + } + + return nil +} + +type authGroupPermissionJoins[Q dialect.Joinable] struct { + typ string + PermissionAuthPermission modAs[Q, authPermissionColumns] + GroupAuthGroup modAs[Q, authGroupColumns] +} + +func (j authGroupPermissionJoins[Q]) aliasedAs(alias string) authGroupPermissionJoins[Q] { + return buildAuthGroupPermissionJoins[Q](buildAuthGroupPermissionColumns(alias), j.typ) +} + +func buildAuthGroupPermissionJoins[Q dialect.Joinable](cols authGroupPermissionColumns, typ string) authGroupPermissionJoins[Q] { + return authGroupPermissionJoins[Q]{ + typ: typ, + PermissionAuthPermission: modAs[Q, authPermissionColumns]{ + c: AuthPermissions.Columns, + f: func(to authPermissionColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthPermissions.Name().As(to.Alias())).On( + to.ID.EQ(cols.PermissionID), + )) + } + + return mods + }, + }, + GroupAuthGroup: modAs[Q, authGroupColumns]{ + c: AuthGroups.Columns, + f: func(to authGroupColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthGroups.Name().As(to.Alias())).On( + to.ID.EQ(cols.GroupID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/auth_permission.bob.go b/database/storage_service/models/auth_permission.bob.go new file mode 100644 index 0000000..fff655a --- /dev/null +++ b/database/storage_service/models/auth_permission.bob.go @@ -0,0 +1,1016 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// AuthPermission is an object representing the database table. +type AuthPermission struct { + ID int32 `db:"id,pk,autoincr" ` + Name string `db:"name" ` + ContentTypeID int32 `db:"content_type_id" ` + Codename string `db:"codename" ` + + R authPermissionR `db:"-" ` +} + +// AuthPermissionSlice is an alias for a slice of pointers to AuthPermission. +// This should almost always be used instead of []*AuthPermission. +type AuthPermissionSlice []*AuthPermission + +// AuthPermissions contains methods to work with the auth_permission table +var AuthPermissions = mysql.NewTablex[*AuthPermission, AuthPermissionSlice, *AuthPermissionSetter]("auth_permission", buildAuthPermissionColumns("auth_permission"), []string{"id"}, []string{"content_type_id", "codename"}) + +// AuthPermissionsQuery is a query on the auth_permission table +type AuthPermissionsQuery = *mysql.ViewQuery[*AuthPermission, AuthPermissionSlice] + +// authPermissionR is where relationships are stored. +type authPermissionR struct { + PermissionAuthGroupPermissions AuthGroupPermissionSlice // auth_group_permissio_permission_id_84c5c92e_fk_auth_perm + ContentTypeDjangoContentType *DjangoContentType // auth_permission_content_type_id_2f476e4b_fk_django_co + PermissionAuthUserUserPermissions AuthUserUserPermissionSlice // auth_user_user_permi_permission_id_1fbb5f2c_fk_auth_perm +} + +func buildAuthPermissionColumns(alias string) authPermissionColumns { + return authPermissionColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "name", "content_type_id", "codename", + ).WithParent("auth_permission"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Name: mysql.Quote(alias, "name"), + ContentTypeID: mysql.Quote(alias, "content_type_id"), + Codename: mysql.Quote(alias, "codename"), + } +} + +type authPermissionColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Name mysql.Expression + ContentTypeID mysql.Expression + Codename mysql.Expression +} + +func (c authPermissionColumns) Alias() string { + return c.tableAlias +} + +func (authPermissionColumns) AliasedAs(alias string) authPermissionColumns { + return buildAuthPermissionColumns(alias) +} + +// AuthPermissionSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type AuthPermissionSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Name omit.Val[string] `db:"name" ` + ContentTypeID omit.Val[int32] `db:"content_type_id" ` + Codename omit.Val[string] `db:"codename" ` +} + +func (s AuthPermissionSetter) SetColumns() []string { + vals := make([]string, 0, 4) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Name.IsValue() { + vals = append(vals, "name") + } + if s.ContentTypeID.IsValue() { + vals = append(vals, "content_type_id") + } + if s.Codename.IsValue() { + vals = append(vals, "codename") + } + return vals +} + +func (s AuthPermissionSetter) Overwrite(t *AuthPermission) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Name.IsValue() { + t.Name = s.Name.MustGet() + } + if s.ContentTypeID.IsValue() { + t.ContentTypeID = s.ContentTypeID.MustGet() + } + if s.Codename.IsValue() { + t.Codename = s.Codename.MustGet() + } +} + +func (s *AuthPermissionSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthPermissions.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Name.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Name.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ContentTypeID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ContentTypeID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Codename.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Codename.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s AuthPermissionSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("auth_permission")...) +} + +func (s AuthPermissionSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 4) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Name.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "name")...), + mysql.Arg(s.Name), + }}) + } + + if s.ContentTypeID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "content_type_id")...), + mysql.Arg(s.ContentTypeID), + }}) + } + + if s.Codename.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "codename")...), + mysql.Arg(s.Codename), + }}) + } + + return exprs +} + +// FindAuthPermission retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindAuthPermission(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*AuthPermission, error) { + if len(cols) == 0 { + return AuthPermissions.Query( + sm.Where(AuthPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return AuthPermissions.Query( + sm.Where(AuthPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(AuthPermissions.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// AuthPermissionExists checks the presence of a single record by primary key +func AuthPermissionExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return AuthPermissions.Query( + sm.Where(AuthPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after AuthPermission is retrieved from the database +func (o *AuthPermission) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthPermissions.AfterSelectHooks.RunHooks(ctx, exec, AuthPermissionSlice{o}) + case bob.QueryTypeInsert: + ctx, err = AuthPermissions.AfterInsertHooks.RunHooks(ctx, exec, AuthPermissionSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = AuthPermissions.AfterUpdateHooks.RunHooks(ctx, exec, AuthPermissionSlice{o}) + case bob.QueryTypeDelete: + ctx, err = AuthPermissions.AfterDeleteHooks.RunHooks(ctx, exec, AuthPermissionSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the AuthPermission +func (o *AuthPermission) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *AuthPermission) pkEQ() dialect.Expression { + return mysql.Quote("auth_permission", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the AuthPermission +func (o *AuthPermission) Update(ctx context.Context, exec bob.Executor, s *AuthPermissionSetter) error { + _, err := AuthPermissions.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single AuthPermission record with an executor +func (o *AuthPermission) Delete(ctx context.Context, exec bob.Executor) error { + _, err := AuthPermissions.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the AuthPermission using the executor +func (o *AuthPermission) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := AuthPermissions.Query( + sm.Where(AuthPermissions.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after AuthPermissionSlice is retrieved from the database +func (o AuthPermissionSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthPermissions.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = AuthPermissions.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = AuthPermissions.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = AuthPermissions.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o AuthPermissionSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("auth_permission", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o AuthPermissionSlice) copyMatchingRows(from ...*AuthPermission) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o AuthPermissionSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthPermissions.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthPermission: + o.copyMatchingRows(retrieved) + case []*AuthPermission: + o.copyMatchingRows(retrieved...) + case AuthPermissionSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthPermission or a slice of AuthPermission + // then run the AfterUpdateHooks on the slice + _, err = AuthPermissions.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o AuthPermissionSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthPermissions.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthPermission: + o.copyMatchingRows(retrieved) + case []*AuthPermission: + o.copyMatchingRows(retrieved...) + case AuthPermissionSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthPermission or a slice of AuthPermission + // then run the AfterDeleteHooks on the slice + _, err = AuthPermissions.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o AuthPermissionSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals AuthPermissionSetter) error { + _, err := AuthPermissions.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o AuthPermissionSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := AuthPermissions.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o AuthPermissionSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := AuthPermissions.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// PermissionAuthGroupPermissions starts a query for related objects on auth_group_permissions +func (o *AuthPermission) PermissionAuthGroupPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthGroupPermissionsQuery { + return AuthGroupPermissions.Query(append(mods, + sm.Where(AuthGroupPermissions.Columns.PermissionID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthPermissionSlice) PermissionAuthGroupPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthGroupPermissionsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthGroupPermissions.Query(append(mods, + sm.Where(mysql.Group(AuthGroupPermissions.Columns.PermissionID).OP("IN", PKArgExpr)), + )...) +} + +// ContentTypeDjangoContentType starts a query for related objects on django_content_type +func (o *AuthPermission) ContentTypeDjangoContentType(mods ...bob.Mod[*dialect.SelectQuery]) DjangoContentTypesQuery { + return DjangoContentTypes.Query(append(mods, + sm.Where(DjangoContentTypes.Columns.ID.EQ(mysql.Arg(o.ContentTypeID))), + )...) +} + +func (os AuthPermissionSlice) ContentTypeDjangoContentType(mods ...bob.Mod[*dialect.SelectQuery]) DjangoContentTypesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ContentTypeID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return DjangoContentTypes.Query(append(mods, + sm.Where(mysql.Group(DjangoContentTypes.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// PermissionAuthUserUserPermissions starts a query for related objects on auth_user_user_permissions +func (o *AuthPermission) PermissionAuthUserUserPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthUserUserPermissionsQuery { + return AuthUserUserPermissions.Query(append(mods, + sm.Where(AuthUserUserPermissions.Columns.PermissionID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthPermissionSlice) PermissionAuthUserUserPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthUserUserPermissionsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUserUserPermissions.Query(append(mods, + sm.Where(mysql.Group(AuthUserUserPermissions.Columns.PermissionID).OP("IN", PKArgExpr)), + )...) +} + +func insertAuthPermissionPermissionAuthGroupPermissions0(ctx context.Context, exec bob.Executor, authGroupPermissions1 []*AuthGroupPermissionSetter, authPermission0 *AuthPermission) (AuthGroupPermissionSlice, error) { + for i := range authGroupPermissions1 { + authGroupPermissions1[i].PermissionID = omit.From(authPermission0.ID) + } + + ret, err := AuthGroupPermissions.Insert(bob.ToMods(authGroupPermissions1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthPermissionPermissionAuthGroupPermissions0: %w", err) + } + + return ret, nil +} + +func attachAuthPermissionPermissionAuthGroupPermissions0(ctx context.Context, exec bob.Executor, count int, authGroupPermissions1 AuthGroupPermissionSlice, authPermission0 *AuthPermission) (AuthGroupPermissionSlice, error) { + setter := &AuthGroupPermissionSetter{ + PermissionID: omit.From(authPermission0.ID), + } + + err := authGroupPermissions1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAuthPermissionPermissionAuthGroupPermissions0: %w", err) + } + + return authGroupPermissions1, nil +} + +func (authPermission0 *AuthPermission) InsertPermissionAuthGroupPermissions(ctx context.Context, exec bob.Executor, related ...*AuthGroupPermissionSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + authGroupPermissions1, err := insertAuthPermissionPermissionAuthGroupPermissions0(ctx, exec, related, authPermission0) + if err != nil { + return err + } + + authPermission0.R.PermissionAuthGroupPermissions = append(authPermission0.R.PermissionAuthGroupPermissions, authGroupPermissions1...) + + for _, rel := range authGroupPermissions1 { + rel.R.PermissionAuthPermission = authPermission0 + } + return nil +} + +func (authPermission0 *AuthPermission) AttachPermissionAuthGroupPermissions(ctx context.Context, exec bob.Executor, related ...*AuthGroupPermission) error { + if len(related) == 0 { + return nil + } + + var err error + authGroupPermissions1 := AuthGroupPermissionSlice(related) + + _, err = attachAuthPermissionPermissionAuthGroupPermissions0(ctx, exec, len(related), authGroupPermissions1, authPermission0) + if err != nil { + return err + } + + authPermission0.R.PermissionAuthGroupPermissions = append(authPermission0.R.PermissionAuthGroupPermissions, authGroupPermissions1...) + + for _, rel := range related { + rel.R.PermissionAuthPermission = authPermission0 + } + + return nil +} + +func attachAuthPermissionContentTypeDjangoContentType0(ctx context.Context, exec bob.Executor, count int, authPermission0 *AuthPermission, djangoContentType1 *DjangoContentType) (*AuthPermission, error) { + setter := &AuthPermissionSetter{ + ContentTypeID: omit.From(djangoContentType1.ID), + } + + err := authPermission0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachAuthPermissionContentTypeDjangoContentType0: %w", err) + } + + return authPermission0, nil +} + +func (authPermission0 *AuthPermission) InsertContentTypeDjangoContentType(ctx context.Context, exec bob.Executor, related *DjangoContentTypeSetter) error { + var err error + + djangoContentType1, err := DjangoContentTypes.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachAuthPermissionContentTypeDjangoContentType0(ctx, exec, 1, authPermission0, djangoContentType1) + if err != nil { + return err + } + + authPermission0.R.ContentTypeDjangoContentType = djangoContentType1 + + djangoContentType1.R.ContentTypeAuthPermissions = append(djangoContentType1.R.ContentTypeAuthPermissions, authPermission0) + + return nil +} + +func (authPermission0 *AuthPermission) AttachContentTypeDjangoContentType(ctx context.Context, exec bob.Executor, djangoContentType1 *DjangoContentType) error { + var err error + + _, err = attachAuthPermissionContentTypeDjangoContentType0(ctx, exec, 1, authPermission0, djangoContentType1) + if err != nil { + return err + } + + authPermission0.R.ContentTypeDjangoContentType = djangoContentType1 + + djangoContentType1.R.ContentTypeAuthPermissions = append(djangoContentType1.R.ContentTypeAuthPermissions, authPermission0) + + return nil +} + +func insertAuthPermissionPermissionAuthUserUserPermissions0(ctx context.Context, exec bob.Executor, authUserUserPermissions1 []*AuthUserUserPermissionSetter, authPermission0 *AuthPermission) (AuthUserUserPermissionSlice, error) { + for i := range authUserUserPermissions1 { + authUserUserPermissions1[i].PermissionID = omit.From(authPermission0.ID) + } + + ret, err := AuthUserUserPermissions.Insert(bob.ToMods(authUserUserPermissions1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthPermissionPermissionAuthUserUserPermissions0: %w", err) + } + + return ret, nil +} + +func attachAuthPermissionPermissionAuthUserUserPermissions0(ctx context.Context, exec bob.Executor, count int, authUserUserPermissions1 AuthUserUserPermissionSlice, authPermission0 *AuthPermission) (AuthUserUserPermissionSlice, error) { + setter := &AuthUserUserPermissionSetter{ + PermissionID: omit.From(authPermission0.ID), + } + + err := authUserUserPermissions1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAuthPermissionPermissionAuthUserUserPermissions0: %w", err) + } + + return authUserUserPermissions1, nil +} + +func (authPermission0 *AuthPermission) InsertPermissionAuthUserUserPermissions(ctx context.Context, exec bob.Executor, related ...*AuthUserUserPermissionSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + authUserUserPermissions1, err := insertAuthPermissionPermissionAuthUserUserPermissions0(ctx, exec, related, authPermission0) + if err != nil { + return err + } + + authPermission0.R.PermissionAuthUserUserPermissions = append(authPermission0.R.PermissionAuthUserUserPermissions, authUserUserPermissions1...) + + for _, rel := range authUserUserPermissions1 { + rel.R.PermissionAuthPermission = authPermission0 + } + return nil +} + +func (authPermission0 *AuthPermission) AttachPermissionAuthUserUserPermissions(ctx context.Context, exec bob.Executor, related ...*AuthUserUserPermission) error { + if len(related) == 0 { + return nil + } + + var err error + authUserUserPermissions1 := AuthUserUserPermissionSlice(related) + + _, err = attachAuthPermissionPermissionAuthUserUserPermissions0(ctx, exec, len(related), authUserUserPermissions1, authPermission0) + if err != nil { + return err + } + + authPermission0.R.PermissionAuthUserUserPermissions = append(authPermission0.R.PermissionAuthUserUserPermissions, authUserUserPermissions1...) + + for _, rel := range related { + rel.R.PermissionAuthPermission = authPermission0 + } + + return nil +} + +type authPermissionWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Name mysql.WhereMod[Q, string] + ContentTypeID mysql.WhereMod[Q, int32] + Codename mysql.WhereMod[Q, string] +} + +func (authPermissionWhere[Q]) AliasedAs(alias string) authPermissionWhere[Q] { + return buildAuthPermissionWhere[Q](buildAuthPermissionColumns(alias)) +} + +func buildAuthPermissionWhere[Q mysql.Filterable](cols authPermissionColumns) authPermissionWhere[Q] { + return authPermissionWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Name: mysql.Where[Q, string](cols.Name), + ContentTypeID: mysql.Where[Q, int32](cols.ContentTypeID), + Codename: mysql.Where[Q, string](cols.Codename), + } +} + +func (o *AuthPermission) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "PermissionAuthGroupPermissions": + rels, ok := retrieved.(AuthGroupPermissionSlice) + if !ok { + return fmt.Errorf("authPermission cannot load %T as %q", retrieved, name) + } + + o.R.PermissionAuthGroupPermissions = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PermissionAuthPermission = o + } + } + return nil + case "ContentTypeDjangoContentType": + rel, ok := retrieved.(*DjangoContentType) + if !ok { + return fmt.Errorf("authPermission cannot load %T as %q", retrieved, name) + } + + o.R.ContentTypeDjangoContentType = rel + + if rel != nil { + rel.R.ContentTypeAuthPermissions = AuthPermissionSlice{o} + } + return nil + case "PermissionAuthUserUserPermissions": + rels, ok := retrieved.(AuthUserUserPermissionSlice) + if !ok { + return fmt.Errorf("authPermission cannot load %T as %q", retrieved, name) + } + + o.R.PermissionAuthUserUserPermissions = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PermissionAuthPermission = o + } + } + return nil + default: + return fmt.Errorf("authPermission has no relationship %q", name) + } +} + +type authPermissionPreloader struct { + ContentTypeDjangoContentType func(...mysql.PreloadOption) mysql.Preloader +} + +func buildAuthPermissionPreloader() authPermissionPreloader { + return authPermissionPreloader{ + ContentTypeDjangoContentType: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*DjangoContentType, DjangoContentTypeSlice](mysql.PreloadRel{ + Name: "ContentTypeDjangoContentType", + Sides: []mysql.PreloadSide{ + { + From: AuthPermissions, + To: DjangoContentTypes, + FromColumns: []string{"content_type_id"}, + ToColumns: []string{"id"}, + }, + }, + }, DjangoContentTypes.Columns.Names(), opts...) + }, + } +} + +type authPermissionThenLoader[Q orm.Loadable] struct { + PermissionAuthGroupPermissions func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ContentTypeDjangoContentType func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PermissionAuthUserUserPermissions func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildAuthPermissionThenLoader[Q orm.Loadable]() authPermissionThenLoader[Q] { + type PermissionAuthGroupPermissionsLoadInterface interface { + LoadPermissionAuthGroupPermissions(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ContentTypeDjangoContentTypeLoadInterface interface { + LoadContentTypeDjangoContentType(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PermissionAuthUserUserPermissionsLoadInterface interface { + LoadPermissionAuthUserUserPermissions(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return authPermissionThenLoader[Q]{ + PermissionAuthGroupPermissions: thenLoadBuilder[Q]( + "PermissionAuthGroupPermissions", + func(ctx context.Context, exec bob.Executor, retrieved PermissionAuthGroupPermissionsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPermissionAuthGroupPermissions(ctx, exec, mods...) + }, + ), + ContentTypeDjangoContentType: thenLoadBuilder[Q]( + "ContentTypeDjangoContentType", + func(ctx context.Context, exec bob.Executor, retrieved ContentTypeDjangoContentTypeLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadContentTypeDjangoContentType(ctx, exec, mods...) + }, + ), + PermissionAuthUserUserPermissions: thenLoadBuilder[Q]( + "PermissionAuthUserUserPermissions", + func(ctx context.Context, exec bob.Executor, retrieved PermissionAuthUserUserPermissionsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPermissionAuthUserUserPermissions(ctx, exec, mods...) + }, + ), + } +} + +// LoadPermissionAuthGroupPermissions loads the authPermission's PermissionAuthGroupPermissions into the .R struct +func (o *AuthPermission) LoadPermissionAuthGroupPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PermissionAuthGroupPermissions = nil + + related, err := o.PermissionAuthGroupPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PermissionAuthPermission = o + } + + o.R.PermissionAuthGroupPermissions = related + return nil +} + +// LoadPermissionAuthGroupPermissions loads the authPermission's PermissionAuthGroupPermissions into the .R struct +func (os AuthPermissionSlice) LoadPermissionAuthGroupPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authGroupPermissions, err := os.PermissionAuthGroupPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PermissionAuthGroupPermissions = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authGroupPermissions { + + if !(o.ID == rel.PermissionID) { + continue + } + + rel.R.PermissionAuthPermission = o + + o.R.PermissionAuthGroupPermissions = append(o.R.PermissionAuthGroupPermissions, rel) + } + } + + return nil +} + +// LoadContentTypeDjangoContentType loads the authPermission's ContentTypeDjangoContentType into the .R struct +func (o *AuthPermission) LoadContentTypeDjangoContentType(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ContentTypeDjangoContentType = nil + + related, err := o.ContentTypeDjangoContentType(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.ContentTypeAuthPermissions = AuthPermissionSlice{o} + + o.R.ContentTypeDjangoContentType = related + return nil +} + +// LoadContentTypeDjangoContentType loads the authPermission's ContentTypeDjangoContentType into the .R struct +func (os AuthPermissionSlice) LoadContentTypeDjangoContentType(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + djangoContentTypes, err := os.ContentTypeDjangoContentType(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range djangoContentTypes { + + if !(o.ContentTypeID == rel.ID) { + continue + } + + rel.R.ContentTypeAuthPermissions = append(rel.R.ContentTypeAuthPermissions, o) + + o.R.ContentTypeDjangoContentType = rel + break + } + } + + return nil +} + +// LoadPermissionAuthUserUserPermissions loads the authPermission's PermissionAuthUserUserPermissions into the .R struct +func (o *AuthPermission) LoadPermissionAuthUserUserPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PermissionAuthUserUserPermissions = nil + + related, err := o.PermissionAuthUserUserPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PermissionAuthPermission = o + } + + o.R.PermissionAuthUserUserPermissions = related + return nil +} + +// LoadPermissionAuthUserUserPermissions loads the authPermission's PermissionAuthUserUserPermissions into the .R struct +func (os AuthPermissionSlice) LoadPermissionAuthUserUserPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUserUserPermissions, err := os.PermissionAuthUserUserPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PermissionAuthUserUserPermissions = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUserUserPermissions { + + if !(o.ID == rel.PermissionID) { + continue + } + + rel.R.PermissionAuthPermission = o + + o.R.PermissionAuthUserUserPermissions = append(o.R.PermissionAuthUserUserPermissions, rel) + } + } + + return nil +} + +type authPermissionJoins[Q dialect.Joinable] struct { + typ string + PermissionAuthGroupPermissions modAs[Q, authGroupPermissionColumns] + ContentTypeDjangoContentType modAs[Q, djangoContentTypeColumns] + PermissionAuthUserUserPermissions modAs[Q, authUserUserPermissionColumns] +} + +func (j authPermissionJoins[Q]) aliasedAs(alias string) authPermissionJoins[Q] { + return buildAuthPermissionJoins[Q](buildAuthPermissionColumns(alias), j.typ) +} + +func buildAuthPermissionJoins[Q dialect.Joinable](cols authPermissionColumns, typ string) authPermissionJoins[Q] { + return authPermissionJoins[Q]{ + typ: typ, + PermissionAuthGroupPermissions: modAs[Q, authGroupPermissionColumns]{ + c: AuthGroupPermissions.Columns, + f: func(to authGroupPermissionColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthGroupPermissions.Name().As(to.Alias())).On( + to.PermissionID.EQ(cols.ID), + )) + } + + return mods + }, + }, + ContentTypeDjangoContentType: modAs[Q, djangoContentTypeColumns]{ + c: DjangoContentTypes.Columns, + f: func(to djangoContentTypeColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, DjangoContentTypes.Name().As(to.Alias())).On( + to.ID.EQ(cols.ContentTypeID), + )) + } + + return mods + }, + }, + PermissionAuthUserUserPermissions: modAs[Q, authUserUserPermissionColumns]{ + c: AuthUserUserPermissions.Columns, + f: func(to authUserUserPermissionColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUserUserPermissions.Name().As(to.Alias())).On( + to.PermissionID.EQ(cols.ID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/auth_user.bob.go b/database/storage_service/models/auth_user.bob.go new file mode 100644 index 0000000..bbe08d8 --- /dev/null +++ b/database/storage_service/models/auth_user.bob.go @@ -0,0 +1,1572 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// AuthUser is an object representing the database table. +type AuthUser struct { + ID int32 `db:"id,pk,autoincr" ` + Password string `db:"password" ` + LastLogin null.Val[time.Time] `db:"last_login" ` + IsSuperuser bool `db:"is_superuser" ` + Username string `db:"username" ` + FirstName string `db:"first_name" ` + LastName string `db:"last_name" ` + Email string `db:"email" ` + IsStaff bool `db:"is_staff" ` + IsActive bool `db:"is_active" ` + DateJoined time.Time `db:"date_joined" ` + + R authUserR `db:"-" ` +} + +// AuthUserSlice is an alias for a slice of pointers to AuthUser. +// This should almost always be used instead of []*AuthUser. +type AuthUserSlice []*AuthUser + +// AuthUsers contains methods to work with the auth_user table +var AuthUsers = mysql.NewTablex[*AuthUser, AuthUserSlice, *AuthUserSetter]("auth_user", buildAuthUserColumns("auth_user"), []string{"id"}, []string{"username"}) + +// AuthUsersQuery is a query on the auth_user table +type AuthUsersQuery = *mysql.ViewQuery[*AuthUser, AuthUserSlice] + +// authUserR is where relationships are stored. +type authUserR struct { + UserAuthUserGroups AuthUserGroupSlice // auth_user_groups_user_id_6a12ed8b_fk_auth_user_id + UserAuthUserUserPermissions AuthUserUserPermissionSlice // auth_user_user_permissions_user_id_a95ead1b_fk_auth_user_id + UserDjangoAdminLogs DjangoAdminLogSlice // django_admin_log_user_id_c564eba6_fk_auth_user_id + AdminIDLocationsEvents LocationsEventSlice // locations_event_admin_id_id_4a50d36a_fk_auth_user_id + UserTastypieApikey *TastypieApikey // tastypie_apikey_user_id_8c8fa920_fk_auth_user_id +} + +func buildAuthUserColumns(alias string) authUserColumns { + return authUserColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "password", "last_login", "is_superuser", "username", "first_name", "last_name", "email", "is_staff", "is_active", "date_joined", + ).WithParent("auth_user"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Password: mysql.Quote(alias, "password"), + LastLogin: mysql.Quote(alias, "last_login"), + IsSuperuser: mysql.Quote(alias, "is_superuser"), + Username: mysql.Quote(alias, "username"), + FirstName: mysql.Quote(alias, "first_name"), + LastName: mysql.Quote(alias, "last_name"), + Email: mysql.Quote(alias, "email"), + IsStaff: mysql.Quote(alias, "is_staff"), + IsActive: mysql.Quote(alias, "is_active"), + DateJoined: mysql.Quote(alias, "date_joined"), + } +} + +type authUserColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Password mysql.Expression + LastLogin mysql.Expression + IsSuperuser mysql.Expression + Username mysql.Expression + FirstName mysql.Expression + LastName mysql.Expression + Email mysql.Expression + IsStaff mysql.Expression + IsActive mysql.Expression + DateJoined mysql.Expression +} + +func (c authUserColumns) Alias() string { + return c.tableAlias +} + +func (authUserColumns) AliasedAs(alias string) authUserColumns { + return buildAuthUserColumns(alias) +} + +// AuthUserSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type AuthUserSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Password omit.Val[string] `db:"password" ` + LastLogin omitnull.Val[time.Time] `db:"last_login" ` + IsSuperuser omit.Val[bool] `db:"is_superuser" ` + Username omit.Val[string] `db:"username" ` + FirstName omit.Val[string] `db:"first_name" ` + LastName omit.Val[string] `db:"last_name" ` + Email omit.Val[string] `db:"email" ` + IsStaff omit.Val[bool] `db:"is_staff" ` + IsActive omit.Val[bool] `db:"is_active" ` + DateJoined omit.Val[time.Time] `db:"date_joined" ` +} + +func (s AuthUserSetter) SetColumns() []string { + vals := make([]string, 0, 11) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Password.IsValue() { + vals = append(vals, "password") + } + if !s.LastLogin.IsUnset() { + vals = append(vals, "last_login") + } + if s.IsSuperuser.IsValue() { + vals = append(vals, "is_superuser") + } + if s.Username.IsValue() { + vals = append(vals, "username") + } + if s.FirstName.IsValue() { + vals = append(vals, "first_name") + } + if s.LastName.IsValue() { + vals = append(vals, "last_name") + } + if s.Email.IsValue() { + vals = append(vals, "email") + } + if s.IsStaff.IsValue() { + vals = append(vals, "is_staff") + } + if s.IsActive.IsValue() { + vals = append(vals, "is_active") + } + if s.DateJoined.IsValue() { + vals = append(vals, "date_joined") + } + return vals +} + +func (s AuthUserSetter) Overwrite(t *AuthUser) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Password.IsValue() { + t.Password = s.Password.MustGet() + } + if !s.LastLogin.IsUnset() { + t.LastLogin = s.LastLogin.MustGetNull() + } + if s.IsSuperuser.IsValue() { + t.IsSuperuser = s.IsSuperuser.MustGet() + } + if s.Username.IsValue() { + t.Username = s.Username.MustGet() + } + if s.FirstName.IsValue() { + t.FirstName = s.FirstName.MustGet() + } + if s.LastName.IsValue() { + t.LastName = s.LastName.MustGet() + } + if s.Email.IsValue() { + t.Email = s.Email.MustGet() + } + if s.IsStaff.IsValue() { + t.IsStaff = s.IsStaff.MustGet() + } + if s.IsActive.IsValue() { + t.IsActive = s.IsActive.MustGet() + } + if s.DateJoined.IsValue() { + t.DateJoined = s.DateJoined.MustGet() + } +} + +func (s *AuthUserSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUsers.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Password.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Password.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.LastLogin.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.LastLogin.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.IsSuperuser.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.IsSuperuser.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Username.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Username.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.FirstName.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.FirstName.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.LastName.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.LastName.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Email.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Email.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.IsStaff.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.IsStaff.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.IsActive.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.IsActive.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DateJoined.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DateJoined.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s AuthUserSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("auth_user")...) +} + +func (s AuthUserSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 11) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Password.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "password")...), + mysql.Arg(s.Password), + }}) + } + + if !s.LastLogin.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "last_login")...), + mysql.Arg(s.LastLogin), + }}) + } + + if s.IsSuperuser.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "is_superuser")...), + mysql.Arg(s.IsSuperuser), + }}) + } + + if s.Username.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "username")...), + mysql.Arg(s.Username), + }}) + } + + if s.FirstName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "first_name")...), + mysql.Arg(s.FirstName), + }}) + } + + if s.LastName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "last_name")...), + mysql.Arg(s.LastName), + }}) + } + + if s.Email.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "email")...), + mysql.Arg(s.Email), + }}) + } + + if s.IsStaff.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "is_staff")...), + mysql.Arg(s.IsStaff), + }}) + } + + if s.IsActive.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "is_active")...), + mysql.Arg(s.IsActive), + }}) + } + + if s.DateJoined.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "date_joined")...), + mysql.Arg(s.DateJoined), + }}) + } + + return exprs +} + +// FindAuthUser retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindAuthUser(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*AuthUser, error) { + if len(cols) == 0 { + return AuthUsers.Query( + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return AuthUsers.Query( + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(AuthUsers.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// AuthUserExists checks the presence of a single record by primary key +func AuthUserExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return AuthUsers.Query( + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after AuthUser is retrieved from the database +func (o *AuthUser) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthUsers.AfterSelectHooks.RunHooks(ctx, exec, AuthUserSlice{o}) + case bob.QueryTypeInsert: + ctx, err = AuthUsers.AfterInsertHooks.RunHooks(ctx, exec, AuthUserSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = AuthUsers.AfterUpdateHooks.RunHooks(ctx, exec, AuthUserSlice{o}) + case bob.QueryTypeDelete: + ctx, err = AuthUsers.AfterDeleteHooks.RunHooks(ctx, exec, AuthUserSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the AuthUser +func (o *AuthUser) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *AuthUser) pkEQ() dialect.Expression { + return mysql.Quote("auth_user", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the AuthUser +func (o *AuthUser) Update(ctx context.Context, exec bob.Executor, s *AuthUserSetter) error { + _, err := AuthUsers.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single AuthUser record with an executor +func (o *AuthUser) Delete(ctx context.Context, exec bob.Executor) error { + _, err := AuthUsers.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the AuthUser using the executor +func (o *AuthUser) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := AuthUsers.Query( + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after AuthUserSlice is retrieved from the database +func (o AuthUserSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthUsers.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = AuthUsers.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = AuthUsers.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = AuthUsers.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o AuthUserSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("auth_user", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o AuthUserSlice) copyMatchingRows(from ...*AuthUser) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o AuthUserSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUsers.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthUser: + o.copyMatchingRows(retrieved) + case []*AuthUser: + o.copyMatchingRows(retrieved...) + case AuthUserSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthUser or a slice of AuthUser + // then run the AfterUpdateHooks on the slice + _, err = AuthUsers.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o AuthUserSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUsers.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthUser: + o.copyMatchingRows(retrieved) + case []*AuthUser: + o.copyMatchingRows(retrieved...) + case AuthUserSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthUser or a slice of AuthUser + // then run the AfterDeleteHooks on the slice + _, err = AuthUsers.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o AuthUserSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals AuthUserSetter) error { + _, err := AuthUsers.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o AuthUserSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := AuthUsers.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o AuthUserSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := AuthUsers.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// UserAuthUserGroups starts a query for related objects on auth_user_groups +func (o *AuthUser) UserAuthUserGroups(mods ...bob.Mod[*dialect.SelectQuery]) AuthUserGroupsQuery { + return AuthUserGroups.Query(append(mods, + sm.Where(AuthUserGroups.Columns.UserID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthUserSlice) UserAuthUserGroups(mods ...bob.Mod[*dialect.SelectQuery]) AuthUserGroupsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUserGroups.Query(append(mods, + sm.Where(mysql.Group(AuthUserGroups.Columns.UserID).OP("IN", PKArgExpr)), + )...) +} + +// UserAuthUserUserPermissions starts a query for related objects on auth_user_user_permissions +func (o *AuthUser) UserAuthUserUserPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthUserUserPermissionsQuery { + return AuthUserUserPermissions.Query(append(mods, + sm.Where(AuthUserUserPermissions.Columns.UserID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthUserSlice) UserAuthUserUserPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthUserUserPermissionsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUserUserPermissions.Query(append(mods, + sm.Where(mysql.Group(AuthUserUserPermissions.Columns.UserID).OP("IN", PKArgExpr)), + )...) +} + +// UserDjangoAdminLogs starts a query for related objects on django_admin_log +func (o *AuthUser) UserDjangoAdminLogs(mods ...bob.Mod[*dialect.SelectQuery]) DjangoAdminLogsQuery { + return DjangoAdminLogs.Query(append(mods, + sm.Where(DjangoAdminLogs.Columns.UserID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthUserSlice) UserDjangoAdminLogs(mods ...bob.Mod[*dialect.SelectQuery]) DjangoAdminLogsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return DjangoAdminLogs.Query(append(mods, + sm.Where(mysql.Group(DjangoAdminLogs.Columns.UserID).OP("IN", PKArgExpr)), + )...) +} + +// AdminIDLocationsEvents starts a query for related objects on locations_event +func (o *AuthUser) AdminIDLocationsEvents(mods ...bob.Mod[*dialect.SelectQuery]) LocationsEventsQuery { + return LocationsEvents.Query(append(mods, + sm.Where(LocationsEvents.Columns.AdminIDID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthUserSlice) AdminIDLocationsEvents(mods ...bob.Mod[*dialect.SelectQuery]) LocationsEventsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsEvents.Query(append(mods, + sm.Where(mysql.Group(LocationsEvents.Columns.AdminIDID).OP("IN", PKArgExpr)), + )...) +} + +// UserTastypieApikey starts a query for related objects on tastypie_apikey +func (o *AuthUser) UserTastypieApikey(mods ...bob.Mod[*dialect.SelectQuery]) TastypieApikeysQuery { + return TastypieApikeys.Query(append(mods, + sm.Where(TastypieApikeys.Columns.UserID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os AuthUserSlice) UserTastypieApikey(mods ...bob.Mod[*dialect.SelectQuery]) TastypieApikeysQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return TastypieApikeys.Query(append(mods, + sm.Where(mysql.Group(TastypieApikeys.Columns.UserID).OP("IN", PKArgExpr)), + )...) +} + +func insertAuthUserUserAuthUserGroups0(ctx context.Context, exec bob.Executor, authUserGroups1 []*AuthUserGroupSetter, authUser0 *AuthUser) (AuthUserGroupSlice, error) { + for i := range authUserGroups1 { + authUserGroups1[i].UserID = omit.From(authUser0.ID) + } + + ret, err := AuthUserGroups.Insert(bob.ToMods(authUserGroups1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthUserUserAuthUserGroups0: %w", err) + } + + return ret, nil +} + +func attachAuthUserUserAuthUserGroups0(ctx context.Context, exec bob.Executor, count int, authUserGroups1 AuthUserGroupSlice, authUser0 *AuthUser) (AuthUserGroupSlice, error) { + setter := &AuthUserGroupSetter{ + UserID: omit.From(authUser0.ID), + } + + err := authUserGroups1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserUserAuthUserGroups0: %w", err) + } + + return authUserGroups1, nil +} + +func (authUser0 *AuthUser) InsertUserAuthUserGroups(ctx context.Context, exec bob.Executor, related ...*AuthUserGroupSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + authUserGroups1, err := insertAuthUserUserAuthUserGroups0(ctx, exec, related, authUser0) + if err != nil { + return err + } + + authUser0.R.UserAuthUserGroups = append(authUser0.R.UserAuthUserGroups, authUserGroups1...) + + for _, rel := range authUserGroups1 { + rel.R.UserAuthUser = authUser0 + } + return nil +} + +func (authUser0 *AuthUser) AttachUserAuthUserGroups(ctx context.Context, exec bob.Executor, related ...*AuthUserGroup) error { + if len(related) == 0 { + return nil + } + + var err error + authUserGroups1 := AuthUserGroupSlice(related) + + _, err = attachAuthUserUserAuthUserGroups0(ctx, exec, len(related), authUserGroups1, authUser0) + if err != nil { + return err + } + + authUser0.R.UserAuthUserGroups = append(authUser0.R.UserAuthUserGroups, authUserGroups1...) + + for _, rel := range related { + rel.R.UserAuthUser = authUser0 + } + + return nil +} + +func insertAuthUserUserAuthUserUserPermissions0(ctx context.Context, exec bob.Executor, authUserUserPermissions1 []*AuthUserUserPermissionSetter, authUser0 *AuthUser) (AuthUserUserPermissionSlice, error) { + for i := range authUserUserPermissions1 { + authUserUserPermissions1[i].UserID = omit.From(authUser0.ID) + } + + ret, err := AuthUserUserPermissions.Insert(bob.ToMods(authUserUserPermissions1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthUserUserAuthUserUserPermissions0: %w", err) + } + + return ret, nil +} + +func attachAuthUserUserAuthUserUserPermissions0(ctx context.Context, exec bob.Executor, count int, authUserUserPermissions1 AuthUserUserPermissionSlice, authUser0 *AuthUser) (AuthUserUserPermissionSlice, error) { + setter := &AuthUserUserPermissionSetter{ + UserID: omit.From(authUser0.ID), + } + + err := authUserUserPermissions1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserUserAuthUserUserPermissions0: %w", err) + } + + return authUserUserPermissions1, nil +} + +func (authUser0 *AuthUser) InsertUserAuthUserUserPermissions(ctx context.Context, exec bob.Executor, related ...*AuthUserUserPermissionSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + authUserUserPermissions1, err := insertAuthUserUserAuthUserUserPermissions0(ctx, exec, related, authUser0) + if err != nil { + return err + } + + authUser0.R.UserAuthUserUserPermissions = append(authUser0.R.UserAuthUserUserPermissions, authUserUserPermissions1...) + + for _, rel := range authUserUserPermissions1 { + rel.R.UserAuthUser = authUser0 + } + return nil +} + +func (authUser0 *AuthUser) AttachUserAuthUserUserPermissions(ctx context.Context, exec bob.Executor, related ...*AuthUserUserPermission) error { + if len(related) == 0 { + return nil + } + + var err error + authUserUserPermissions1 := AuthUserUserPermissionSlice(related) + + _, err = attachAuthUserUserAuthUserUserPermissions0(ctx, exec, len(related), authUserUserPermissions1, authUser0) + if err != nil { + return err + } + + authUser0.R.UserAuthUserUserPermissions = append(authUser0.R.UserAuthUserUserPermissions, authUserUserPermissions1...) + + for _, rel := range related { + rel.R.UserAuthUser = authUser0 + } + + return nil +} + +func insertAuthUserUserDjangoAdminLogs0(ctx context.Context, exec bob.Executor, djangoAdminLogs1 []*DjangoAdminLogSetter, authUser0 *AuthUser) (DjangoAdminLogSlice, error) { + for i := range djangoAdminLogs1 { + djangoAdminLogs1[i].UserID = omit.From(authUser0.ID) + } + + ret, err := DjangoAdminLogs.Insert(bob.ToMods(djangoAdminLogs1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthUserUserDjangoAdminLogs0: %w", err) + } + + return ret, nil +} + +func attachAuthUserUserDjangoAdminLogs0(ctx context.Context, exec bob.Executor, count int, djangoAdminLogs1 DjangoAdminLogSlice, authUser0 *AuthUser) (DjangoAdminLogSlice, error) { + setter := &DjangoAdminLogSetter{ + UserID: omit.From(authUser0.ID), + } + + err := djangoAdminLogs1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserUserDjangoAdminLogs0: %w", err) + } + + return djangoAdminLogs1, nil +} + +func (authUser0 *AuthUser) InsertUserDjangoAdminLogs(ctx context.Context, exec bob.Executor, related ...*DjangoAdminLogSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + djangoAdminLogs1, err := insertAuthUserUserDjangoAdminLogs0(ctx, exec, related, authUser0) + if err != nil { + return err + } + + authUser0.R.UserDjangoAdminLogs = append(authUser0.R.UserDjangoAdminLogs, djangoAdminLogs1...) + + for _, rel := range djangoAdminLogs1 { + rel.R.UserAuthUser = authUser0 + } + return nil +} + +func (authUser0 *AuthUser) AttachUserDjangoAdminLogs(ctx context.Context, exec bob.Executor, related ...*DjangoAdminLog) error { + if len(related) == 0 { + return nil + } + + var err error + djangoAdminLogs1 := DjangoAdminLogSlice(related) + + _, err = attachAuthUserUserDjangoAdminLogs0(ctx, exec, len(related), djangoAdminLogs1, authUser0) + if err != nil { + return err + } + + authUser0.R.UserDjangoAdminLogs = append(authUser0.R.UserDjangoAdminLogs, djangoAdminLogs1...) + + for _, rel := range related { + rel.R.UserAuthUser = authUser0 + } + + return nil +} + +func insertAuthUserAdminIDLocationsEvents0(ctx context.Context, exec bob.Executor, locationsEvents1 []*LocationsEventSetter, authUser0 *AuthUser) (LocationsEventSlice, error) { + for i := range locationsEvents1 { + locationsEvents1[i].AdminIDID = omitnull.From(authUser0.ID) + } + + ret, err := LocationsEvents.Insert(bob.ToMods(locationsEvents1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthUserAdminIDLocationsEvents0: %w", err) + } + + return ret, nil +} + +func attachAuthUserAdminIDLocationsEvents0(ctx context.Context, exec bob.Executor, count int, locationsEvents1 LocationsEventSlice, authUser0 *AuthUser) (LocationsEventSlice, error) { + setter := &LocationsEventSetter{ + AdminIDID: omitnull.From(authUser0.ID), + } + + err := locationsEvents1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserAdminIDLocationsEvents0: %w", err) + } + + return locationsEvents1, nil +} + +func (authUser0 *AuthUser) InsertAdminIDLocationsEvents(ctx context.Context, exec bob.Executor, related ...*LocationsEventSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsEvents1, err := insertAuthUserAdminIDLocationsEvents0(ctx, exec, related, authUser0) + if err != nil { + return err + } + + authUser0.R.AdminIDLocationsEvents = append(authUser0.R.AdminIDLocationsEvents, locationsEvents1...) + + for _, rel := range locationsEvents1 { + rel.R.AdminIDAuthUser = authUser0 + } + return nil +} + +func (authUser0 *AuthUser) AttachAdminIDLocationsEvents(ctx context.Context, exec bob.Executor, related ...*LocationsEvent) error { + if len(related) == 0 { + return nil + } + + var err error + locationsEvents1 := LocationsEventSlice(related) + + _, err = attachAuthUserAdminIDLocationsEvents0(ctx, exec, len(related), locationsEvents1, authUser0) + if err != nil { + return err + } + + authUser0.R.AdminIDLocationsEvents = append(authUser0.R.AdminIDLocationsEvents, locationsEvents1...) + + for _, rel := range related { + rel.R.AdminIDAuthUser = authUser0 + } + + return nil +} + +func insertAuthUserUserTastypieApikey0(ctx context.Context, exec bob.Executor, tastypieApikey1 *TastypieApikeySetter, authUser0 *AuthUser) (*TastypieApikey, error) { + tastypieApikey1.UserID = omit.From(authUser0.ID) + + ret, err := TastypieApikeys.Insert(tastypieApikey1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertAuthUserUserTastypieApikey0: %w", err) + } + + return ret, nil +} + +func attachAuthUserUserTastypieApikey0(ctx context.Context, exec bob.Executor, count int, tastypieApikey1 *TastypieApikey, authUser0 *AuthUser) (*TastypieApikey, error) { + setter := &TastypieApikeySetter{ + UserID: omit.From(authUser0.ID), + } + + err := tastypieApikey1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserUserTastypieApikey0: %w", err) + } + + return tastypieApikey1, nil +} + +func (authUser0 *AuthUser) InsertUserTastypieApikey(ctx context.Context, exec bob.Executor, related *TastypieApikeySetter) error { + var err error + + tastypieApikey1, err := insertAuthUserUserTastypieApikey0(ctx, exec, related, authUser0) + if err != nil { + return err + } + + authUser0.R.UserTastypieApikey = tastypieApikey1 + + tastypieApikey1.R.UserAuthUser = authUser0 + + return nil +} + +func (authUser0 *AuthUser) AttachUserTastypieApikey(ctx context.Context, exec bob.Executor, tastypieApikey1 *TastypieApikey) error { + var err error + + _, err = attachAuthUserUserTastypieApikey0(ctx, exec, 1, tastypieApikey1, authUser0) + if err != nil { + return err + } + + authUser0.R.UserTastypieApikey = tastypieApikey1 + + tastypieApikey1.R.UserAuthUser = authUser0 + + return nil +} + +type authUserWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Password mysql.WhereMod[Q, string] + LastLogin mysql.WhereNullMod[Q, time.Time] + IsSuperuser mysql.WhereMod[Q, bool] + Username mysql.WhereMod[Q, string] + FirstName mysql.WhereMod[Q, string] + LastName mysql.WhereMod[Q, string] + Email mysql.WhereMod[Q, string] + IsStaff mysql.WhereMod[Q, bool] + IsActive mysql.WhereMod[Q, bool] + DateJoined mysql.WhereMod[Q, time.Time] +} + +func (authUserWhere[Q]) AliasedAs(alias string) authUserWhere[Q] { + return buildAuthUserWhere[Q](buildAuthUserColumns(alias)) +} + +func buildAuthUserWhere[Q mysql.Filterable](cols authUserColumns) authUserWhere[Q] { + return authUserWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Password: mysql.Where[Q, string](cols.Password), + LastLogin: mysql.WhereNull[Q, time.Time](cols.LastLogin), + IsSuperuser: mysql.Where[Q, bool](cols.IsSuperuser), + Username: mysql.Where[Q, string](cols.Username), + FirstName: mysql.Where[Q, string](cols.FirstName), + LastName: mysql.Where[Q, string](cols.LastName), + Email: mysql.Where[Q, string](cols.Email), + IsStaff: mysql.Where[Q, bool](cols.IsStaff), + IsActive: mysql.Where[Q, bool](cols.IsActive), + DateJoined: mysql.Where[Q, time.Time](cols.DateJoined), + } +} + +func (o *AuthUser) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "UserAuthUserGroups": + rels, ok := retrieved.(AuthUserGroupSlice) + if !ok { + return fmt.Errorf("authUser cannot load %T as %q", retrieved, name) + } + + o.R.UserAuthUserGroups = rels + + for _, rel := range rels { + if rel != nil { + rel.R.UserAuthUser = o + } + } + return nil + case "UserAuthUserUserPermissions": + rels, ok := retrieved.(AuthUserUserPermissionSlice) + if !ok { + return fmt.Errorf("authUser cannot load %T as %q", retrieved, name) + } + + o.R.UserAuthUserUserPermissions = rels + + for _, rel := range rels { + if rel != nil { + rel.R.UserAuthUser = o + } + } + return nil + case "UserDjangoAdminLogs": + rels, ok := retrieved.(DjangoAdminLogSlice) + if !ok { + return fmt.Errorf("authUser cannot load %T as %q", retrieved, name) + } + + o.R.UserDjangoAdminLogs = rels + + for _, rel := range rels { + if rel != nil { + rel.R.UserAuthUser = o + } + } + return nil + case "AdminIDLocationsEvents": + rels, ok := retrieved.(LocationsEventSlice) + if !ok { + return fmt.Errorf("authUser cannot load %T as %q", retrieved, name) + } + + o.R.AdminIDLocationsEvents = rels + + for _, rel := range rels { + if rel != nil { + rel.R.AdminIDAuthUser = o + } + } + return nil + case "UserTastypieApikey": + rel, ok := retrieved.(*TastypieApikey) + if !ok { + return fmt.Errorf("authUser cannot load %T as %q", retrieved, name) + } + + o.R.UserTastypieApikey = rel + + if rel != nil { + rel.R.UserAuthUser = o + } + return nil + default: + return fmt.Errorf("authUser has no relationship %q", name) + } +} + +type authUserPreloader struct { + UserTastypieApikey func(...mysql.PreloadOption) mysql.Preloader +} + +func buildAuthUserPreloader() authUserPreloader { + return authUserPreloader{ + UserTastypieApikey: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*TastypieApikey, TastypieApikeySlice](mysql.PreloadRel{ + Name: "UserTastypieApikey", + Sides: []mysql.PreloadSide{ + { + From: AuthUsers, + To: TastypieApikeys, + FromColumns: []string{"id"}, + ToColumns: []string{"user_id"}, + }, + }, + }, TastypieApikeys.Columns.Names(), opts...) + }, + } +} + +type authUserThenLoader[Q orm.Loadable] struct { + UserAuthUserGroups func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + UserAuthUserUserPermissions func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + UserDjangoAdminLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + AdminIDLocationsEvents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + UserTastypieApikey func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildAuthUserThenLoader[Q orm.Loadable]() authUserThenLoader[Q] { + type UserAuthUserGroupsLoadInterface interface { + LoadUserAuthUserGroups(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type UserAuthUserUserPermissionsLoadInterface interface { + LoadUserAuthUserUserPermissions(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type UserDjangoAdminLogsLoadInterface interface { + LoadUserDjangoAdminLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type AdminIDLocationsEventsLoadInterface interface { + LoadAdminIDLocationsEvents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type UserTastypieApikeyLoadInterface interface { + LoadUserTastypieApikey(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return authUserThenLoader[Q]{ + UserAuthUserGroups: thenLoadBuilder[Q]( + "UserAuthUserGroups", + func(ctx context.Context, exec bob.Executor, retrieved UserAuthUserGroupsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUserAuthUserGroups(ctx, exec, mods...) + }, + ), + UserAuthUserUserPermissions: thenLoadBuilder[Q]( + "UserAuthUserUserPermissions", + func(ctx context.Context, exec bob.Executor, retrieved UserAuthUserUserPermissionsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUserAuthUserUserPermissions(ctx, exec, mods...) + }, + ), + UserDjangoAdminLogs: thenLoadBuilder[Q]( + "UserDjangoAdminLogs", + func(ctx context.Context, exec bob.Executor, retrieved UserDjangoAdminLogsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUserDjangoAdminLogs(ctx, exec, mods...) + }, + ), + AdminIDLocationsEvents: thenLoadBuilder[Q]( + "AdminIDLocationsEvents", + func(ctx context.Context, exec bob.Executor, retrieved AdminIDLocationsEventsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadAdminIDLocationsEvents(ctx, exec, mods...) + }, + ), + UserTastypieApikey: thenLoadBuilder[Q]( + "UserTastypieApikey", + func(ctx context.Context, exec bob.Executor, retrieved UserTastypieApikeyLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUserTastypieApikey(ctx, exec, mods...) + }, + ), + } +} + +// LoadUserAuthUserGroups loads the authUser's UserAuthUserGroups into the .R struct +func (o *AuthUser) LoadUserAuthUserGroups(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UserAuthUserGroups = nil + + related, err := o.UserAuthUserGroups(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.UserAuthUser = o + } + + o.R.UserAuthUserGroups = related + return nil +} + +// LoadUserAuthUserGroups loads the authUser's UserAuthUserGroups into the .R struct +func (os AuthUserSlice) LoadUserAuthUserGroups(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUserGroups, err := os.UserAuthUserGroups(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.UserAuthUserGroups = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUserGroups { + + if !(o.ID == rel.UserID) { + continue + } + + rel.R.UserAuthUser = o + + o.R.UserAuthUserGroups = append(o.R.UserAuthUserGroups, rel) + } + } + + return nil +} + +// LoadUserAuthUserUserPermissions loads the authUser's UserAuthUserUserPermissions into the .R struct +func (o *AuthUser) LoadUserAuthUserUserPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UserAuthUserUserPermissions = nil + + related, err := o.UserAuthUserUserPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.UserAuthUser = o + } + + o.R.UserAuthUserUserPermissions = related + return nil +} + +// LoadUserAuthUserUserPermissions loads the authUser's UserAuthUserUserPermissions into the .R struct +func (os AuthUserSlice) LoadUserAuthUserUserPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUserUserPermissions, err := os.UserAuthUserUserPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.UserAuthUserUserPermissions = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUserUserPermissions { + + if !(o.ID == rel.UserID) { + continue + } + + rel.R.UserAuthUser = o + + o.R.UserAuthUserUserPermissions = append(o.R.UserAuthUserUserPermissions, rel) + } + } + + return nil +} + +// LoadUserDjangoAdminLogs loads the authUser's UserDjangoAdminLogs into the .R struct +func (o *AuthUser) LoadUserDjangoAdminLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UserDjangoAdminLogs = nil + + related, err := o.UserDjangoAdminLogs(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.UserAuthUser = o + } + + o.R.UserDjangoAdminLogs = related + return nil +} + +// LoadUserDjangoAdminLogs loads the authUser's UserDjangoAdminLogs into the .R struct +func (os AuthUserSlice) LoadUserDjangoAdminLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + djangoAdminLogs, err := os.UserDjangoAdminLogs(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.UserDjangoAdminLogs = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range djangoAdminLogs { + + if !(o.ID == rel.UserID) { + continue + } + + rel.R.UserAuthUser = o + + o.R.UserDjangoAdminLogs = append(o.R.UserDjangoAdminLogs, rel) + } + } + + return nil +} + +// LoadAdminIDLocationsEvents loads the authUser's AdminIDLocationsEvents into the .R struct +func (o *AuthUser) LoadAdminIDLocationsEvents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.AdminIDLocationsEvents = nil + + related, err := o.AdminIDLocationsEvents(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.AdminIDAuthUser = o + } + + o.R.AdminIDLocationsEvents = related + return nil +} + +// LoadAdminIDLocationsEvents loads the authUser's AdminIDLocationsEvents into the .R struct +func (os AuthUserSlice) LoadAdminIDLocationsEvents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsEvents, err := os.AdminIDLocationsEvents(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.AdminIDLocationsEvents = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsEvents { + + if !rel.AdminIDID.IsValue() { + continue + } + if !(rel.AdminIDID.IsValue() && o.ID == rel.AdminIDID.MustGet()) { + continue + } + + rel.R.AdminIDAuthUser = o + + o.R.AdminIDLocationsEvents = append(o.R.AdminIDLocationsEvents, rel) + } + } + + return nil +} + +// LoadUserTastypieApikey loads the authUser's UserTastypieApikey into the .R struct +func (o *AuthUser) LoadUserTastypieApikey(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UserTastypieApikey = nil + + related, err := o.UserTastypieApikey(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.UserAuthUser = o + + o.R.UserTastypieApikey = related + return nil +} + +// LoadUserTastypieApikey loads the authUser's UserTastypieApikey into the .R struct +func (os AuthUserSlice) LoadUserTastypieApikey(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + tastypieApikeys, err := os.UserTastypieApikey(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range tastypieApikeys { + + if !(o.ID == rel.UserID) { + continue + } + + rel.R.UserAuthUser = o + + o.R.UserTastypieApikey = rel + break + } + } + + return nil +} + +type authUserJoins[Q dialect.Joinable] struct { + typ string + UserAuthUserGroups modAs[Q, authUserGroupColumns] + UserAuthUserUserPermissions modAs[Q, authUserUserPermissionColumns] + UserDjangoAdminLogs modAs[Q, djangoAdminLogColumns] + AdminIDLocationsEvents modAs[Q, locationsEventColumns] + UserTastypieApikey modAs[Q, tastypieApikeyColumns] +} + +func (j authUserJoins[Q]) aliasedAs(alias string) authUserJoins[Q] { + return buildAuthUserJoins[Q](buildAuthUserColumns(alias), j.typ) +} + +func buildAuthUserJoins[Q dialect.Joinable](cols authUserColumns, typ string) authUserJoins[Q] { + return authUserJoins[Q]{ + typ: typ, + UserAuthUserGroups: modAs[Q, authUserGroupColumns]{ + c: AuthUserGroups.Columns, + f: func(to authUserGroupColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUserGroups.Name().As(to.Alias())).On( + to.UserID.EQ(cols.ID), + )) + } + + return mods + }, + }, + UserAuthUserUserPermissions: modAs[Q, authUserUserPermissionColumns]{ + c: AuthUserUserPermissions.Columns, + f: func(to authUserUserPermissionColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUserUserPermissions.Name().As(to.Alias())).On( + to.UserID.EQ(cols.ID), + )) + } + + return mods + }, + }, + UserDjangoAdminLogs: modAs[Q, djangoAdminLogColumns]{ + c: DjangoAdminLogs.Columns, + f: func(to djangoAdminLogColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, DjangoAdminLogs.Name().As(to.Alias())).On( + to.UserID.EQ(cols.ID), + )) + } + + return mods + }, + }, + AdminIDLocationsEvents: modAs[Q, locationsEventColumns]{ + c: LocationsEvents.Columns, + f: func(to locationsEventColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsEvents.Name().As(to.Alias())).On( + to.AdminIDID.EQ(cols.ID), + )) + } + + return mods + }, + }, + UserTastypieApikey: modAs[Q, tastypieApikeyColumns]{ + c: TastypieApikeys.Columns, + f: func(to tastypieApikeyColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, TastypieApikeys.Name().As(to.Alias())).On( + to.UserID.EQ(cols.ID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/auth_user_groups.bob.go b/database/storage_service/models/auth_user_groups.bob.go new file mode 100644 index 0000000..d76ee3c --- /dev/null +++ b/database/storage_service/models/auth_user_groups.bob.go @@ -0,0 +1,787 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// AuthUserGroup is an object representing the database table. +type AuthUserGroup struct { + ID int32 `db:"id,pk,autoincr" ` + UserID int32 `db:"user_id" ` + GroupID int32 `db:"group_id" ` + + R authUserGroupR `db:"-" ` +} + +// AuthUserGroupSlice is an alias for a slice of pointers to AuthUserGroup. +// This should almost always be used instead of []*AuthUserGroup. +type AuthUserGroupSlice []*AuthUserGroup + +// AuthUserGroups contains methods to work with the auth_user_groups table +var AuthUserGroups = mysql.NewTablex[*AuthUserGroup, AuthUserGroupSlice, *AuthUserGroupSetter]("auth_user_groups", buildAuthUserGroupColumns("auth_user_groups"), []string{"id"}, []string{"user_id", "group_id"}) + +// AuthUserGroupsQuery is a query on the auth_user_groups table +type AuthUserGroupsQuery = *mysql.ViewQuery[*AuthUserGroup, AuthUserGroupSlice] + +// authUserGroupR is where relationships are stored. +type authUserGroupR struct { + GroupAuthGroup *AuthGroup // auth_user_groups_group_id_97559544_fk_auth_group_id + UserAuthUser *AuthUser // auth_user_groups_user_id_6a12ed8b_fk_auth_user_id +} + +func buildAuthUserGroupColumns(alias string) authUserGroupColumns { + return authUserGroupColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "user_id", "group_id", + ).WithParent("auth_user_groups"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UserID: mysql.Quote(alias, "user_id"), + GroupID: mysql.Quote(alias, "group_id"), + } +} + +type authUserGroupColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UserID mysql.Expression + GroupID mysql.Expression +} + +func (c authUserGroupColumns) Alias() string { + return c.tableAlias +} + +func (authUserGroupColumns) AliasedAs(alias string) authUserGroupColumns { + return buildAuthUserGroupColumns(alias) +} + +// AuthUserGroupSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type AuthUserGroupSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UserID omit.Val[int32] `db:"user_id" ` + GroupID omit.Val[int32] `db:"group_id" ` +} + +func (s AuthUserGroupSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UserID.IsValue() { + vals = append(vals, "user_id") + } + if s.GroupID.IsValue() { + vals = append(vals, "group_id") + } + return vals +} + +func (s AuthUserGroupSetter) Overwrite(t *AuthUserGroup) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UserID.IsValue() { + t.UserID = s.UserID.MustGet() + } + if s.GroupID.IsValue() { + t.GroupID = s.GroupID.MustGet() + } +} + +func (s *AuthUserGroupSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUserGroups.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UserID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UserID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.GroupID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.GroupID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s AuthUserGroupSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("auth_user_groups")...) +} + +func (s AuthUserGroupSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UserID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "user_id")...), + mysql.Arg(s.UserID), + }}) + } + + if s.GroupID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "group_id")...), + mysql.Arg(s.GroupID), + }}) + } + + return exprs +} + +// FindAuthUserGroup retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindAuthUserGroup(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*AuthUserGroup, error) { + if len(cols) == 0 { + return AuthUserGroups.Query( + sm.Where(AuthUserGroups.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return AuthUserGroups.Query( + sm.Where(AuthUserGroups.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(AuthUserGroups.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// AuthUserGroupExists checks the presence of a single record by primary key +func AuthUserGroupExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return AuthUserGroups.Query( + sm.Where(AuthUserGroups.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after AuthUserGroup is retrieved from the database +func (o *AuthUserGroup) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthUserGroups.AfterSelectHooks.RunHooks(ctx, exec, AuthUserGroupSlice{o}) + case bob.QueryTypeInsert: + ctx, err = AuthUserGroups.AfterInsertHooks.RunHooks(ctx, exec, AuthUserGroupSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = AuthUserGroups.AfterUpdateHooks.RunHooks(ctx, exec, AuthUserGroupSlice{o}) + case bob.QueryTypeDelete: + ctx, err = AuthUserGroups.AfterDeleteHooks.RunHooks(ctx, exec, AuthUserGroupSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the AuthUserGroup +func (o *AuthUserGroup) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *AuthUserGroup) pkEQ() dialect.Expression { + return mysql.Quote("auth_user_groups", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the AuthUserGroup +func (o *AuthUserGroup) Update(ctx context.Context, exec bob.Executor, s *AuthUserGroupSetter) error { + _, err := AuthUserGroups.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single AuthUserGroup record with an executor +func (o *AuthUserGroup) Delete(ctx context.Context, exec bob.Executor) error { + _, err := AuthUserGroups.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the AuthUserGroup using the executor +func (o *AuthUserGroup) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := AuthUserGroups.Query( + sm.Where(AuthUserGroups.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after AuthUserGroupSlice is retrieved from the database +func (o AuthUserGroupSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthUserGroups.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = AuthUserGroups.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = AuthUserGroups.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = AuthUserGroups.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o AuthUserGroupSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("auth_user_groups", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o AuthUserGroupSlice) copyMatchingRows(from ...*AuthUserGroup) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o AuthUserGroupSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUserGroups.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthUserGroup: + o.copyMatchingRows(retrieved) + case []*AuthUserGroup: + o.copyMatchingRows(retrieved...) + case AuthUserGroupSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthUserGroup or a slice of AuthUserGroup + // then run the AfterUpdateHooks on the slice + _, err = AuthUserGroups.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o AuthUserGroupSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUserGroups.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthUserGroup: + o.copyMatchingRows(retrieved) + case []*AuthUserGroup: + o.copyMatchingRows(retrieved...) + case AuthUserGroupSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthUserGroup or a slice of AuthUserGroup + // then run the AfterDeleteHooks on the slice + _, err = AuthUserGroups.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o AuthUserGroupSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals AuthUserGroupSetter) error { + _, err := AuthUserGroups.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o AuthUserGroupSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := AuthUserGroups.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o AuthUserGroupSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := AuthUserGroups.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// GroupAuthGroup starts a query for related objects on auth_group +func (o *AuthUserGroup) GroupAuthGroup(mods ...bob.Mod[*dialect.SelectQuery]) AuthGroupsQuery { + return AuthGroups.Query(append(mods, + sm.Where(AuthGroups.Columns.ID.EQ(mysql.Arg(o.GroupID))), + )...) +} + +func (os AuthUserGroupSlice) GroupAuthGroup(mods ...bob.Mod[*dialect.SelectQuery]) AuthGroupsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.GroupID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthGroups.Query(append(mods, + sm.Where(mysql.Group(AuthGroups.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// UserAuthUser starts a query for related objects on auth_user +func (o *AuthUserGroup) UserAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + return AuthUsers.Query(append(mods, + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(o.UserID))), + )...) +} + +func (os AuthUserGroupSlice) UserAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UserID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUsers.Query(append(mods, + sm.Where(mysql.Group(AuthUsers.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func attachAuthUserGroupGroupAuthGroup0(ctx context.Context, exec bob.Executor, count int, authUserGroup0 *AuthUserGroup, authGroup1 *AuthGroup) (*AuthUserGroup, error) { + setter := &AuthUserGroupSetter{ + GroupID: omit.From(authGroup1.ID), + } + + err := authUserGroup0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserGroupGroupAuthGroup0: %w", err) + } + + return authUserGroup0, nil +} + +func (authUserGroup0 *AuthUserGroup) InsertGroupAuthGroup(ctx context.Context, exec bob.Executor, related *AuthGroupSetter) error { + var err error + + authGroup1, err := AuthGroups.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachAuthUserGroupGroupAuthGroup0(ctx, exec, 1, authUserGroup0, authGroup1) + if err != nil { + return err + } + + authUserGroup0.R.GroupAuthGroup = authGroup1 + + authGroup1.R.GroupAuthUserGroups = append(authGroup1.R.GroupAuthUserGroups, authUserGroup0) + + return nil +} + +func (authUserGroup0 *AuthUserGroup) AttachGroupAuthGroup(ctx context.Context, exec bob.Executor, authGroup1 *AuthGroup) error { + var err error + + _, err = attachAuthUserGroupGroupAuthGroup0(ctx, exec, 1, authUserGroup0, authGroup1) + if err != nil { + return err + } + + authUserGroup0.R.GroupAuthGroup = authGroup1 + + authGroup1.R.GroupAuthUserGroups = append(authGroup1.R.GroupAuthUserGroups, authUserGroup0) + + return nil +} + +func attachAuthUserGroupUserAuthUser0(ctx context.Context, exec bob.Executor, count int, authUserGroup0 *AuthUserGroup, authUser1 *AuthUser) (*AuthUserGroup, error) { + setter := &AuthUserGroupSetter{ + UserID: omit.From(authUser1.ID), + } + + err := authUserGroup0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserGroupUserAuthUser0: %w", err) + } + + return authUserGroup0, nil +} + +func (authUserGroup0 *AuthUserGroup) InsertUserAuthUser(ctx context.Context, exec bob.Executor, related *AuthUserSetter) error { + var err error + + authUser1, err := AuthUsers.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachAuthUserGroupUserAuthUser0(ctx, exec, 1, authUserGroup0, authUser1) + if err != nil { + return err + } + + authUserGroup0.R.UserAuthUser = authUser1 + + authUser1.R.UserAuthUserGroups = append(authUser1.R.UserAuthUserGroups, authUserGroup0) + + return nil +} + +func (authUserGroup0 *AuthUserGroup) AttachUserAuthUser(ctx context.Context, exec bob.Executor, authUser1 *AuthUser) error { + var err error + + _, err = attachAuthUserGroupUserAuthUser0(ctx, exec, 1, authUserGroup0, authUser1) + if err != nil { + return err + } + + authUserGroup0.R.UserAuthUser = authUser1 + + authUser1.R.UserAuthUserGroups = append(authUser1.R.UserAuthUserGroups, authUserGroup0) + + return nil +} + +type authUserGroupWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UserID mysql.WhereMod[Q, int32] + GroupID mysql.WhereMod[Q, int32] +} + +func (authUserGroupWhere[Q]) AliasedAs(alias string) authUserGroupWhere[Q] { + return buildAuthUserGroupWhere[Q](buildAuthUserGroupColumns(alias)) +} + +func buildAuthUserGroupWhere[Q mysql.Filterable](cols authUserGroupColumns) authUserGroupWhere[Q] { + return authUserGroupWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UserID: mysql.Where[Q, int32](cols.UserID), + GroupID: mysql.Where[Q, int32](cols.GroupID), + } +} + +func (o *AuthUserGroup) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "GroupAuthGroup": + rel, ok := retrieved.(*AuthGroup) + if !ok { + return fmt.Errorf("authUserGroup cannot load %T as %q", retrieved, name) + } + + o.R.GroupAuthGroup = rel + + if rel != nil { + rel.R.GroupAuthUserGroups = AuthUserGroupSlice{o} + } + return nil + case "UserAuthUser": + rel, ok := retrieved.(*AuthUser) + if !ok { + return fmt.Errorf("authUserGroup cannot load %T as %q", retrieved, name) + } + + o.R.UserAuthUser = rel + + if rel != nil { + rel.R.UserAuthUserGroups = AuthUserGroupSlice{o} + } + return nil + default: + return fmt.Errorf("authUserGroup has no relationship %q", name) + } +} + +type authUserGroupPreloader struct { + GroupAuthGroup func(...mysql.PreloadOption) mysql.Preloader + UserAuthUser func(...mysql.PreloadOption) mysql.Preloader +} + +func buildAuthUserGroupPreloader() authUserGroupPreloader { + return authUserGroupPreloader{ + GroupAuthGroup: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthGroup, AuthGroupSlice](mysql.PreloadRel{ + Name: "GroupAuthGroup", + Sides: []mysql.PreloadSide{ + { + From: AuthUserGroups, + To: AuthGroups, + FromColumns: []string{"group_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthGroups.Columns.Names(), opts...) + }, + UserAuthUser: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthUser, AuthUserSlice](mysql.PreloadRel{ + Name: "UserAuthUser", + Sides: []mysql.PreloadSide{ + { + From: AuthUserGroups, + To: AuthUsers, + FromColumns: []string{"user_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthUsers.Columns.Names(), opts...) + }, + } +} + +type authUserGroupThenLoader[Q orm.Loadable] struct { + GroupAuthGroup func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + UserAuthUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildAuthUserGroupThenLoader[Q orm.Loadable]() authUserGroupThenLoader[Q] { + type GroupAuthGroupLoadInterface interface { + LoadGroupAuthGroup(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type UserAuthUserLoadInterface interface { + LoadUserAuthUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return authUserGroupThenLoader[Q]{ + GroupAuthGroup: thenLoadBuilder[Q]( + "GroupAuthGroup", + func(ctx context.Context, exec bob.Executor, retrieved GroupAuthGroupLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadGroupAuthGroup(ctx, exec, mods...) + }, + ), + UserAuthUser: thenLoadBuilder[Q]( + "UserAuthUser", + func(ctx context.Context, exec bob.Executor, retrieved UserAuthUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUserAuthUser(ctx, exec, mods...) + }, + ), + } +} + +// LoadGroupAuthGroup loads the authUserGroup's GroupAuthGroup into the .R struct +func (o *AuthUserGroup) LoadGroupAuthGroup(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.GroupAuthGroup = nil + + related, err := o.GroupAuthGroup(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.GroupAuthUserGroups = AuthUserGroupSlice{o} + + o.R.GroupAuthGroup = related + return nil +} + +// LoadGroupAuthGroup loads the authUserGroup's GroupAuthGroup into the .R struct +func (os AuthUserGroupSlice) LoadGroupAuthGroup(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authGroups, err := os.GroupAuthGroup(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authGroups { + + if !(o.GroupID == rel.ID) { + continue + } + + rel.R.GroupAuthUserGroups = append(rel.R.GroupAuthUserGroups, o) + + o.R.GroupAuthGroup = rel + break + } + } + + return nil +} + +// LoadUserAuthUser loads the authUserGroup's UserAuthUser into the .R struct +func (o *AuthUserGroup) LoadUserAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UserAuthUser = nil + + related, err := o.UserAuthUser(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.UserAuthUserGroups = AuthUserGroupSlice{o} + + o.R.UserAuthUser = related + return nil +} + +// LoadUserAuthUser loads the authUserGroup's UserAuthUser into the .R struct +func (os AuthUserGroupSlice) LoadUserAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUsers, err := os.UserAuthUser(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUsers { + + if !(o.UserID == rel.ID) { + continue + } + + rel.R.UserAuthUserGroups = append(rel.R.UserAuthUserGroups, o) + + o.R.UserAuthUser = rel + break + } + } + + return nil +} + +type authUserGroupJoins[Q dialect.Joinable] struct { + typ string + GroupAuthGroup modAs[Q, authGroupColumns] + UserAuthUser modAs[Q, authUserColumns] +} + +func (j authUserGroupJoins[Q]) aliasedAs(alias string) authUserGroupJoins[Q] { + return buildAuthUserGroupJoins[Q](buildAuthUserGroupColumns(alias), j.typ) +} + +func buildAuthUserGroupJoins[Q dialect.Joinable](cols authUserGroupColumns, typ string) authUserGroupJoins[Q] { + return authUserGroupJoins[Q]{ + typ: typ, + GroupAuthGroup: modAs[Q, authGroupColumns]{ + c: AuthGroups.Columns, + f: func(to authGroupColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthGroups.Name().As(to.Alias())).On( + to.ID.EQ(cols.GroupID), + )) + } + + return mods + }, + }, + UserAuthUser: modAs[Q, authUserColumns]{ + c: AuthUsers.Columns, + f: func(to authUserColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUsers.Name().As(to.Alias())).On( + to.ID.EQ(cols.UserID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/auth_user_user_permissions.bob.go b/database/storage_service/models/auth_user_user_permissions.bob.go new file mode 100644 index 0000000..8bb7633 --- /dev/null +++ b/database/storage_service/models/auth_user_user_permissions.bob.go @@ -0,0 +1,787 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// AuthUserUserPermission is an object representing the database table. +type AuthUserUserPermission struct { + ID int32 `db:"id,pk,autoincr" ` + UserID int32 `db:"user_id" ` + PermissionID int32 `db:"permission_id" ` + + R authUserUserPermissionR `db:"-" ` +} + +// AuthUserUserPermissionSlice is an alias for a slice of pointers to AuthUserUserPermission. +// This should almost always be used instead of []*AuthUserUserPermission. +type AuthUserUserPermissionSlice []*AuthUserUserPermission + +// AuthUserUserPermissions contains methods to work with the auth_user_user_permissions table +var AuthUserUserPermissions = mysql.NewTablex[*AuthUserUserPermission, AuthUserUserPermissionSlice, *AuthUserUserPermissionSetter]("auth_user_user_permissions", buildAuthUserUserPermissionColumns("auth_user_user_permissions"), []string{"id"}, []string{"user_id", "permission_id"}) + +// AuthUserUserPermissionsQuery is a query on the auth_user_user_permissions table +type AuthUserUserPermissionsQuery = *mysql.ViewQuery[*AuthUserUserPermission, AuthUserUserPermissionSlice] + +// authUserUserPermissionR is where relationships are stored. +type authUserUserPermissionR struct { + PermissionAuthPermission *AuthPermission // auth_user_user_permi_permission_id_1fbb5f2c_fk_auth_perm + UserAuthUser *AuthUser // auth_user_user_permissions_user_id_a95ead1b_fk_auth_user_id +} + +func buildAuthUserUserPermissionColumns(alias string) authUserUserPermissionColumns { + return authUserUserPermissionColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "user_id", "permission_id", + ).WithParent("auth_user_user_permissions"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UserID: mysql.Quote(alias, "user_id"), + PermissionID: mysql.Quote(alias, "permission_id"), + } +} + +type authUserUserPermissionColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UserID mysql.Expression + PermissionID mysql.Expression +} + +func (c authUserUserPermissionColumns) Alias() string { + return c.tableAlias +} + +func (authUserUserPermissionColumns) AliasedAs(alias string) authUserUserPermissionColumns { + return buildAuthUserUserPermissionColumns(alias) +} + +// AuthUserUserPermissionSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type AuthUserUserPermissionSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UserID omit.Val[int32] `db:"user_id" ` + PermissionID omit.Val[int32] `db:"permission_id" ` +} + +func (s AuthUserUserPermissionSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UserID.IsValue() { + vals = append(vals, "user_id") + } + if s.PermissionID.IsValue() { + vals = append(vals, "permission_id") + } + return vals +} + +func (s AuthUserUserPermissionSetter) Overwrite(t *AuthUserUserPermission) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UserID.IsValue() { + t.UserID = s.UserID.MustGet() + } + if s.PermissionID.IsValue() { + t.PermissionID = s.PermissionID.MustGet() + } +} + +func (s *AuthUserUserPermissionSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUserUserPermissions.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UserID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UserID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.PermissionID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PermissionID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s AuthUserUserPermissionSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("auth_user_user_permissions")...) +} + +func (s AuthUserUserPermissionSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UserID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "user_id")...), + mysql.Arg(s.UserID), + }}) + } + + if s.PermissionID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "permission_id")...), + mysql.Arg(s.PermissionID), + }}) + } + + return exprs +} + +// FindAuthUserUserPermission retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindAuthUserUserPermission(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*AuthUserUserPermission, error) { + if len(cols) == 0 { + return AuthUserUserPermissions.Query( + sm.Where(AuthUserUserPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return AuthUserUserPermissions.Query( + sm.Where(AuthUserUserPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(AuthUserUserPermissions.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// AuthUserUserPermissionExists checks the presence of a single record by primary key +func AuthUserUserPermissionExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return AuthUserUserPermissions.Query( + sm.Where(AuthUserUserPermissions.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after AuthUserUserPermission is retrieved from the database +func (o *AuthUserUserPermission) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthUserUserPermissions.AfterSelectHooks.RunHooks(ctx, exec, AuthUserUserPermissionSlice{o}) + case bob.QueryTypeInsert: + ctx, err = AuthUserUserPermissions.AfterInsertHooks.RunHooks(ctx, exec, AuthUserUserPermissionSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = AuthUserUserPermissions.AfterUpdateHooks.RunHooks(ctx, exec, AuthUserUserPermissionSlice{o}) + case bob.QueryTypeDelete: + ctx, err = AuthUserUserPermissions.AfterDeleteHooks.RunHooks(ctx, exec, AuthUserUserPermissionSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the AuthUserUserPermission +func (o *AuthUserUserPermission) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *AuthUserUserPermission) pkEQ() dialect.Expression { + return mysql.Quote("auth_user_user_permissions", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the AuthUserUserPermission +func (o *AuthUserUserPermission) Update(ctx context.Context, exec bob.Executor, s *AuthUserUserPermissionSetter) error { + _, err := AuthUserUserPermissions.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single AuthUserUserPermission record with an executor +func (o *AuthUserUserPermission) Delete(ctx context.Context, exec bob.Executor) error { + _, err := AuthUserUserPermissions.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the AuthUserUserPermission using the executor +func (o *AuthUserUserPermission) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := AuthUserUserPermissions.Query( + sm.Where(AuthUserUserPermissions.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after AuthUserUserPermissionSlice is retrieved from the database +func (o AuthUserUserPermissionSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = AuthUserUserPermissions.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = AuthUserUserPermissions.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = AuthUserUserPermissions.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = AuthUserUserPermissions.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o AuthUserUserPermissionSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("auth_user_user_permissions", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o AuthUserUserPermissionSlice) copyMatchingRows(from ...*AuthUserUserPermission) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o AuthUserUserPermissionSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUserUserPermissions.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthUserUserPermission: + o.copyMatchingRows(retrieved) + case []*AuthUserUserPermission: + o.copyMatchingRows(retrieved...) + case AuthUserUserPermissionSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthUserUserPermission or a slice of AuthUserUserPermission + // then run the AfterUpdateHooks on the slice + _, err = AuthUserUserPermissions.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o AuthUserUserPermissionSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return AuthUserUserPermissions.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *AuthUserUserPermission: + o.copyMatchingRows(retrieved) + case []*AuthUserUserPermission: + o.copyMatchingRows(retrieved...) + case AuthUserUserPermissionSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a AuthUserUserPermission or a slice of AuthUserUserPermission + // then run the AfterDeleteHooks on the slice + _, err = AuthUserUserPermissions.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o AuthUserUserPermissionSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals AuthUserUserPermissionSetter) error { + _, err := AuthUserUserPermissions.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o AuthUserUserPermissionSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := AuthUserUserPermissions.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o AuthUserUserPermissionSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := AuthUserUserPermissions.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// PermissionAuthPermission starts a query for related objects on auth_permission +func (o *AuthUserUserPermission) PermissionAuthPermission(mods ...bob.Mod[*dialect.SelectQuery]) AuthPermissionsQuery { + return AuthPermissions.Query(append(mods, + sm.Where(AuthPermissions.Columns.ID.EQ(mysql.Arg(o.PermissionID))), + )...) +} + +func (os AuthUserUserPermissionSlice) PermissionAuthPermission(mods ...bob.Mod[*dialect.SelectQuery]) AuthPermissionsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PermissionID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthPermissions.Query(append(mods, + sm.Where(mysql.Group(AuthPermissions.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// UserAuthUser starts a query for related objects on auth_user +func (o *AuthUserUserPermission) UserAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + return AuthUsers.Query(append(mods, + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(o.UserID))), + )...) +} + +func (os AuthUserUserPermissionSlice) UserAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UserID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUsers.Query(append(mods, + sm.Where(mysql.Group(AuthUsers.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func attachAuthUserUserPermissionPermissionAuthPermission0(ctx context.Context, exec bob.Executor, count int, authUserUserPermission0 *AuthUserUserPermission, authPermission1 *AuthPermission) (*AuthUserUserPermission, error) { + setter := &AuthUserUserPermissionSetter{ + PermissionID: omit.From(authPermission1.ID), + } + + err := authUserUserPermission0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserUserPermissionPermissionAuthPermission0: %w", err) + } + + return authUserUserPermission0, nil +} + +func (authUserUserPermission0 *AuthUserUserPermission) InsertPermissionAuthPermission(ctx context.Context, exec bob.Executor, related *AuthPermissionSetter) error { + var err error + + authPermission1, err := AuthPermissions.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachAuthUserUserPermissionPermissionAuthPermission0(ctx, exec, 1, authUserUserPermission0, authPermission1) + if err != nil { + return err + } + + authUserUserPermission0.R.PermissionAuthPermission = authPermission1 + + authPermission1.R.PermissionAuthUserUserPermissions = append(authPermission1.R.PermissionAuthUserUserPermissions, authUserUserPermission0) + + return nil +} + +func (authUserUserPermission0 *AuthUserUserPermission) AttachPermissionAuthPermission(ctx context.Context, exec bob.Executor, authPermission1 *AuthPermission) error { + var err error + + _, err = attachAuthUserUserPermissionPermissionAuthPermission0(ctx, exec, 1, authUserUserPermission0, authPermission1) + if err != nil { + return err + } + + authUserUserPermission0.R.PermissionAuthPermission = authPermission1 + + authPermission1.R.PermissionAuthUserUserPermissions = append(authPermission1.R.PermissionAuthUserUserPermissions, authUserUserPermission0) + + return nil +} + +func attachAuthUserUserPermissionUserAuthUser0(ctx context.Context, exec bob.Executor, count int, authUserUserPermission0 *AuthUserUserPermission, authUser1 *AuthUser) (*AuthUserUserPermission, error) { + setter := &AuthUserUserPermissionSetter{ + UserID: omit.From(authUser1.ID), + } + + err := authUserUserPermission0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachAuthUserUserPermissionUserAuthUser0: %w", err) + } + + return authUserUserPermission0, nil +} + +func (authUserUserPermission0 *AuthUserUserPermission) InsertUserAuthUser(ctx context.Context, exec bob.Executor, related *AuthUserSetter) error { + var err error + + authUser1, err := AuthUsers.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachAuthUserUserPermissionUserAuthUser0(ctx, exec, 1, authUserUserPermission0, authUser1) + if err != nil { + return err + } + + authUserUserPermission0.R.UserAuthUser = authUser1 + + authUser1.R.UserAuthUserUserPermissions = append(authUser1.R.UserAuthUserUserPermissions, authUserUserPermission0) + + return nil +} + +func (authUserUserPermission0 *AuthUserUserPermission) AttachUserAuthUser(ctx context.Context, exec bob.Executor, authUser1 *AuthUser) error { + var err error + + _, err = attachAuthUserUserPermissionUserAuthUser0(ctx, exec, 1, authUserUserPermission0, authUser1) + if err != nil { + return err + } + + authUserUserPermission0.R.UserAuthUser = authUser1 + + authUser1.R.UserAuthUserUserPermissions = append(authUser1.R.UserAuthUserUserPermissions, authUserUserPermission0) + + return nil +} + +type authUserUserPermissionWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UserID mysql.WhereMod[Q, int32] + PermissionID mysql.WhereMod[Q, int32] +} + +func (authUserUserPermissionWhere[Q]) AliasedAs(alias string) authUserUserPermissionWhere[Q] { + return buildAuthUserUserPermissionWhere[Q](buildAuthUserUserPermissionColumns(alias)) +} + +func buildAuthUserUserPermissionWhere[Q mysql.Filterable](cols authUserUserPermissionColumns) authUserUserPermissionWhere[Q] { + return authUserUserPermissionWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UserID: mysql.Where[Q, int32](cols.UserID), + PermissionID: mysql.Where[Q, int32](cols.PermissionID), + } +} + +func (o *AuthUserUserPermission) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "PermissionAuthPermission": + rel, ok := retrieved.(*AuthPermission) + if !ok { + return fmt.Errorf("authUserUserPermission cannot load %T as %q", retrieved, name) + } + + o.R.PermissionAuthPermission = rel + + if rel != nil { + rel.R.PermissionAuthUserUserPermissions = AuthUserUserPermissionSlice{o} + } + return nil + case "UserAuthUser": + rel, ok := retrieved.(*AuthUser) + if !ok { + return fmt.Errorf("authUserUserPermission cannot load %T as %q", retrieved, name) + } + + o.R.UserAuthUser = rel + + if rel != nil { + rel.R.UserAuthUserUserPermissions = AuthUserUserPermissionSlice{o} + } + return nil + default: + return fmt.Errorf("authUserUserPermission has no relationship %q", name) + } +} + +type authUserUserPermissionPreloader struct { + PermissionAuthPermission func(...mysql.PreloadOption) mysql.Preloader + UserAuthUser func(...mysql.PreloadOption) mysql.Preloader +} + +func buildAuthUserUserPermissionPreloader() authUserUserPermissionPreloader { + return authUserUserPermissionPreloader{ + PermissionAuthPermission: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthPermission, AuthPermissionSlice](mysql.PreloadRel{ + Name: "PermissionAuthPermission", + Sides: []mysql.PreloadSide{ + { + From: AuthUserUserPermissions, + To: AuthPermissions, + FromColumns: []string{"permission_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthPermissions.Columns.Names(), opts...) + }, + UserAuthUser: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthUser, AuthUserSlice](mysql.PreloadRel{ + Name: "UserAuthUser", + Sides: []mysql.PreloadSide{ + { + From: AuthUserUserPermissions, + To: AuthUsers, + FromColumns: []string{"user_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthUsers.Columns.Names(), opts...) + }, + } +} + +type authUserUserPermissionThenLoader[Q orm.Loadable] struct { + PermissionAuthPermission func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + UserAuthUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildAuthUserUserPermissionThenLoader[Q orm.Loadable]() authUserUserPermissionThenLoader[Q] { + type PermissionAuthPermissionLoadInterface interface { + LoadPermissionAuthPermission(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type UserAuthUserLoadInterface interface { + LoadUserAuthUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return authUserUserPermissionThenLoader[Q]{ + PermissionAuthPermission: thenLoadBuilder[Q]( + "PermissionAuthPermission", + func(ctx context.Context, exec bob.Executor, retrieved PermissionAuthPermissionLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPermissionAuthPermission(ctx, exec, mods...) + }, + ), + UserAuthUser: thenLoadBuilder[Q]( + "UserAuthUser", + func(ctx context.Context, exec bob.Executor, retrieved UserAuthUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUserAuthUser(ctx, exec, mods...) + }, + ), + } +} + +// LoadPermissionAuthPermission loads the authUserUserPermission's PermissionAuthPermission into the .R struct +func (o *AuthUserUserPermission) LoadPermissionAuthPermission(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PermissionAuthPermission = nil + + related, err := o.PermissionAuthPermission(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PermissionAuthUserUserPermissions = AuthUserUserPermissionSlice{o} + + o.R.PermissionAuthPermission = related + return nil +} + +// LoadPermissionAuthPermission loads the authUserUserPermission's PermissionAuthPermission into the .R struct +func (os AuthUserUserPermissionSlice) LoadPermissionAuthPermission(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authPermissions, err := os.PermissionAuthPermission(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authPermissions { + + if !(o.PermissionID == rel.ID) { + continue + } + + rel.R.PermissionAuthUserUserPermissions = append(rel.R.PermissionAuthUserUserPermissions, o) + + o.R.PermissionAuthPermission = rel + break + } + } + + return nil +} + +// LoadUserAuthUser loads the authUserUserPermission's UserAuthUser into the .R struct +func (o *AuthUserUserPermission) LoadUserAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UserAuthUser = nil + + related, err := o.UserAuthUser(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.UserAuthUserUserPermissions = AuthUserUserPermissionSlice{o} + + o.R.UserAuthUser = related + return nil +} + +// LoadUserAuthUser loads the authUserUserPermission's UserAuthUser into the .R struct +func (os AuthUserUserPermissionSlice) LoadUserAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUsers, err := os.UserAuthUser(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUsers { + + if !(o.UserID == rel.ID) { + continue + } + + rel.R.UserAuthUserUserPermissions = append(rel.R.UserAuthUserUserPermissions, o) + + o.R.UserAuthUser = rel + break + } + } + + return nil +} + +type authUserUserPermissionJoins[Q dialect.Joinable] struct { + typ string + PermissionAuthPermission modAs[Q, authPermissionColumns] + UserAuthUser modAs[Q, authUserColumns] +} + +func (j authUserUserPermissionJoins[Q]) aliasedAs(alias string) authUserUserPermissionJoins[Q] { + return buildAuthUserUserPermissionJoins[Q](buildAuthUserUserPermissionColumns(alias), j.typ) +} + +func buildAuthUserUserPermissionJoins[Q dialect.Joinable](cols authUserUserPermissionColumns, typ string) authUserUserPermissionJoins[Q] { + return authUserUserPermissionJoins[Q]{ + typ: typ, + PermissionAuthPermission: modAs[Q, authPermissionColumns]{ + c: AuthPermissions.Columns, + f: func(to authPermissionColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthPermissions.Name().As(to.Alias())).On( + to.ID.EQ(cols.PermissionID), + )) + } + + return mods + }, + }, + UserAuthUser: modAs[Q, authUserColumns]{ + c: AuthUsers.Columns, + f: func(to authUserColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUsers.Name().As(to.Alias())).On( + to.ID.EQ(cols.UserID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/bob_joins.bob.go b/database/storage_service/models/bob_joins.bob.go new file mode 100644 index 0000000..cd067d6 --- /dev/null +++ b/database/storage_service/models/bob_joins.bob.go @@ -0,0 +1,146 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "hash/maphash" + + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/clause" + "github.com/stephenafamo/bob/dialect/mysql/dialect" +) + +var ( + SelectJoins = getJoins[*dialect.SelectQuery]() + UpdateJoins = getJoins[*dialect.UpdateQuery]() + DeleteJoins = getJoins[*dialect.DeleteQuery]() +) + +type joinSet[Q interface{ aliasedAs(string) Q }] struct { + InnerJoin Q + LeftJoin Q + RightJoin Q +} + +func (j joinSet[Q]) AliasedAs(alias string) joinSet[Q] { + return joinSet[Q]{ + InnerJoin: j.InnerJoin.aliasedAs(alias), + LeftJoin: j.LeftJoin.aliasedAs(alias), + RightJoin: j.RightJoin.aliasedAs(alias), + } +} + +type joins[Q dialect.Joinable] struct { + AuthGroups joinSet[authGroupJoins[Q]] + AuthGroupPermissions joinSet[authGroupPermissionJoins[Q]] + AuthPermissions joinSet[authPermissionJoins[Q]] + AuthUsers joinSet[authUserJoins[Q]] + AuthUserGroups joinSet[authUserGroupJoins[Q]] + AuthUserUserPermissions joinSet[authUserUserPermissionJoins[Q]] + DjangoAdminLogs joinSet[djangoAdminLogJoins[Q]] + DjangoContentTypes joinSet[djangoContentTypeJoins[Q]] + LocationsArchipelagos joinSet[locationsArchipelagoJoins[Q]] + LocationsArkivums joinSet[locationsArkivumJoins[Q]] + LocationsDataverses joinSet[locationsDataverseJoins[Q]] + LocationsDspaces joinSet[locationsDspaceJoins[Q]] + LocationsDspacerests joinSet[locationsDspacerestJoins[Q]] + LocationsDuraclouds joinSet[locationsDuracloudJoins[Q]] + LocationsEvents joinSet[locationsEventJoins[Q]] + LocationsFedoras joinSet[locationsFedoraJoins[Q]] + LocationsFiles joinSet[locationsFileJoins[Q]] + LocationsFixitylogs joinSet[locationsFixitylogJoins[Q]] + LocationsGPGS joinSet[locationsGPGJoins[Q]] + LocationsLocalfilesystems joinSet[locationsLocalfilesystemJoins[Q]] + LocationsLocations joinSet[locationsLocationJoins[Q]] + LocationsLocationReplicators joinSet[locationsLocationReplicatorJoins[Q]] + LocationsLocationpipelines joinSet[locationsLocationpipelineJoins[Q]] + LocationsLockssomatics joinSet[locationsLockssomaticJoins[Q]] + LocationsNFS joinSet[locationsNFJoins[Q]] + LocationsOfflinereplicastagings joinSet[locationsOfflinereplicastagingJoins[Q]] + LocationsPackages joinSet[locationsPackageJoins[Q]] + LocationsPackageRelatedPackages joinSet[locationsPackageRelatedPackageJoins[Q]] + LocationsPackagedownloadtasks joinSet[locationsPackagedownloadtaskJoins[Q]] + LocationsPackagedownloadtaskfiles joinSet[locationsPackagedownloadtaskfileJoins[Q]] + LocationsPipelines joinSet[locationsPipelineJoins[Q]] + LocationsPipelinelocalfs joinSet[locationsPipelinelocalfJoins[Q]] + LocationsRclones joinSet[locationsRcloneJoins[Q]] + LocationsS3S joinSet[locationsS3Joins[Q]] + LocationsSpaces joinSet[locationsSpaceJoins[Q]] + LocationsSwifts joinSet[locationsSwiftJoins[Q]] + TastypieApikeys joinSet[tastypieApikeyJoins[Q]] +} + +func buildJoinSet[Q interface{ aliasedAs(string) Q }, C any, F func(C, string) Q](c C, f F) joinSet[Q] { + return joinSet[Q]{ + InnerJoin: f(c, clause.InnerJoin), + LeftJoin: f(c, clause.LeftJoin), + RightJoin: f(c, clause.RightJoin), + } +} + +func getJoins[Q dialect.Joinable]() joins[Q] { + return joins[Q]{ + AuthGroups: buildJoinSet[authGroupJoins[Q]](AuthGroups.Columns, buildAuthGroupJoins), + AuthGroupPermissions: buildJoinSet[authGroupPermissionJoins[Q]](AuthGroupPermissions.Columns, buildAuthGroupPermissionJoins), + AuthPermissions: buildJoinSet[authPermissionJoins[Q]](AuthPermissions.Columns, buildAuthPermissionJoins), + AuthUsers: buildJoinSet[authUserJoins[Q]](AuthUsers.Columns, buildAuthUserJoins), + AuthUserGroups: buildJoinSet[authUserGroupJoins[Q]](AuthUserGroups.Columns, buildAuthUserGroupJoins), + AuthUserUserPermissions: buildJoinSet[authUserUserPermissionJoins[Q]](AuthUserUserPermissions.Columns, buildAuthUserUserPermissionJoins), + DjangoAdminLogs: buildJoinSet[djangoAdminLogJoins[Q]](DjangoAdminLogs.Columns, buildDjangoAdminLogJoins), + DjangoContentTypes: buildJoinSet[djangoContentTypeJoins[Q]](DjangoContentTypes.Columns, buildDjangoContentTypeJoins), + LocationsArchipelagos: buildJoinSet[locationsArchipelagoJoins[Q]](LocationsArchipelagos.Columns, buildLocationsArchipelagoJoins), + LocationsArkivums: buildJoinSet[locationsArkivumJoins[Q]](LocationsArkivums.Columns, buildLocationsArkivumJoins), + LocationsDataverses: buildJoinSet[locationsDataverseJoins[Q]](LocationsDataverses.Columns, buildLocationsDataverseJoins), + LocationsDspaces: buildJoinSet[locationsDspaceJoins[Q]](LocationsDspaces.Columns, buildLocationsDspaceJoins), + LocationsDspacerests: buildJoinSet[locationsDspacerestJoins[Q]](LocationsDspacerests.Columns, buildLocationsDspacerestJoins), + LocationsDuraclouds: buildJoinSet[locationsDuracloudJoins[Q]](LocationsDuraclouds.Columns, buildLocationsDuracloudJoins), + LocationsEvents: buildJoinSet[locationsEventJoins[Q]](LocationsEvents.Columns, buildLocationsEventJoins), + LocationsFedoras: buildJoinSet[locationsFedoraJoins[Q]](LocationsFedoras.Columns, buildLocationsFedoraJoins), + LocationsFiles: buildJoinSet[locationsFileJoins[Q]](LocationsFiles.Columns, buildLocationsFileJoins), + LocationsFixitylogs: buildJoinSet[locationsFixitylogJoins[Q]](LocationsFixitylogs.Columns, buildLocationsFixitylogJoins), + LocationsGPGS: buildJoinSet[locationsGPGJoins[Q]](LocationsGPGS.Columns, buildLocationsGPGJoins), + LocationsLocalfilesystems: buildJoinSet[locationsLocalfilesystemJoins[Q]](LocationsLocalfilesystems.Columns, buildLocationsLocalfilesystemJoins), + LocationsLocations: buildJoinSet[locationsLocationJoins[Q]](LocationsLocations.Columns, buildLocationsLocationJoins), + LocationsLocationReplicators: buildJoinSet[locationsLocationReplicatorJoins[Q]](LocationsLocationReplicators.Columns, buildLocationsLocationReplicatorJoins), + LocationsLocationpipelines: buildJoinSet[locationsLocationpipelineJoins[Q]](LocationsLocationpipelines.Columns, buildLocationsLocationpipelineJoins), + LocationsLockssomatics: buildJoinSet[locationsLockssomaticJoins[Q]](LocationsLockssomatics.Columns, buildLocationsLockssomaticJoins), + LocationsNFS: buildJoinSet[locationsNFJoins[Q]](LocationsNFS.Columns, buildLocationsNFJoins), + LocationsOfflinereplicastagings: buildJoinSet[locationsOfflinereplicastagingJoins[Q]](LocationsOfflinereplicastagings.Columns, buildLocationsOfflinereplicastagingJoins), + LocationsPackages: buildJoinSet[locationsPackageJoins[Q]](LocationsPackages.Columns, buildLocationsPackageJoins), + LocationsPackageRelatedPackages: buildJoinSet[locationsPackageRelatedPackageJoins[Q]](LocationsPackageRelatedPackages.Columns, buildLocationsPackageRelatedPackageJoins), + LocationsPackagedownloadtasks: buildJoinSet[locationsPackagedownloadtaskJoins[Q]](LocationsPackagedownloadtasks.Columns, buildLocationsPackagedownloadtaskJoins), + LocationsPackagedownloadtaskfiles: buildJoinSet[locationsPackagedownloadtaskfileJoins[Q]](LocationsPackagedownloadtaskfiles.Columns, buildLocationsPackagedownloadtaskfileJoins), + LocationsPipelines: buildJoinSet[locationsPipelineJoins[Q]](LocationsPipelines.Columns, buildLocationsPipelineJoins), + LocationsPipelinelocalfs: buildJoinSet[locationsPipelinelocalfJoins[Q]](LocationsPipelinelocalfs.Columns, buildLocationsPipelinelocalfJoins), + LocationsRclones: buildJoinSet[locationsRcloneJoins[Q]](LocationsRclones.Columns, buildLocationsRcloneJoins), + LocationsS3S: buildJoinSet[locationsS3Joins[Q]](LocationsS3S.Columns, buildLocationsS3Joins), + LocationsSpaces: buildJoinSet[locationsSpaceJoins[Q]](LocationsSpaces.Columns, buildLocationsSpaceJoins), + LocationsSwifts: buildJoinSet[locationsSwiftJoins[Q]](LocationsSwifts.Columns, buildLocationsSwiftJoins), + TastypieApikeys: buildJoinSet[tastypieApikeyJoins[Q]](TastypieApikeys.Columns, buildTastypieApikeyJoins), + } +} + +type modAs[Q any, C interface{ AliasedAs(string) C }] struct { + c C + f func(C) bob.Mod[Q] +} + +func (m modAs[Q, C]) Apply(q Q) { + m.f(m.c).Apply(q) +} + +func (m modAs[Q, C]) AliasedAs(alias string) bob.Mod[Q] { + m.c = m.c.AliasedAs(alias) + return m +} + +func randInt() int64 { + out := int64(new(maphash.Hash).Sum64()) + + if out < 0 { + return -out % 10000 + } + + return out % 10000 +} diff --git a/database/storage_service/models/bob_loaders.bob.go b/database/storage_service/models/bob_loaders.bob.go new file mode 100644 index 0000000..bc15cec --- /dev/null +++ b/database/storage_service/models/bob_loaders.bob.go @@ -0,0 +1,203 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "database/sql" + "errors" + "fmt" + + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/orm" +) + +var Preload = getPreloaders() + +type preloaders struct { + AuthGroup authGroupPreloader + AuthGroupPermission authGroupPermissionPreloader + AuthPermission authPermissionPreloader + AuthUser authUserPreloader + AuthUserGroup authUserGroupPreloader + AuthUserUserPermission authUserUserPermissionPreloader + DjangoAdminLog djangoAdminLogPreloader + DjangoContentType djangoContentTypePreloader + LocationsArchipelago locationsArchipelagoPreloader + LocationsArkivum locationsArkivumPreloader + LocationsDataverse locationsDataversePreloader + LocationsDspace locationsDspacePreloader + LocationsDspacerest locationsDspacerestPreloader + LocationsDuracloud locationsDuracloudPreloader + LocationsEvent locationsEventPreloader + LocationsFedora locationsFedoraPreloader + LocationsFile locationsFilePreloader + LocationsFixitylog locationsFixitylogPreloader + LocationsGPG locationsGPGPreloader + LocationsLocalfilesystem locationsLocalfilesystemPreloader + LocationsLocation locationsLocationPreloader + LocationsLocationReplicator locationsLocationReplicatorPreloader + LocationsLocationpipeline locationsLocationpipelinePreloader + LocationsLockssomatic locationsLockssomaticPreloader + LocationsNF locationsNFPreloader + LocationsOfflinereplicastaging locationsOfflinereplicastagingPreloader + LocationsPackage locationsPackagePreloader + LocationsPackageRelatedPackage locationsPackageRelatedPackagePreloader + LocationsPackagedownloadtask locationsPackagedownloadtaskPreloader + LocationsPackagedownloadtaskfile locationsPackagedownloadtaskfilePreloader + LocationsPipeline locationsPipelinePreloader + LocationsPipelinelocalf locationsPipelinelocalfPreloader + LocationsRclone locationsRclonePreloader + LocationsS3 locationsS3Preloader + LocationsSpace locationsSpacePreloader + LocationsSwift locationsSwiftPreloader + TastypieApikey tastypieApikeyPreloader +} + +func getPreloaders() preloaders { + return preloaders{ + AuthGroup: buildAuthGroupPreloader(), + AuthGroupPermission: buildAuthGroupPermissionPreloader(), + AuthPermission: buildAuthPermissionPreloader(), + AuthUser: buildAuthUserPreloader(), + AuthUserGroup: buildAuthUserGroupPreloader(), + AuthUserUserPermission: buildAuthUserUserPermissionPreloader(), + DjangoAdminLog: buildDjangoAdminLogPreloader(), + DjangoContentType: buildDjangoContentTypePreloader(), + LocationsArchipelago: buildLocationsArchipelagoPreloader(), + LocationsArkivum: buildLocationsArkivumPreloader(), + LocationsDataverse: buildLocationsDataversePreloader(), + LocationsDspace: buildLocationsDspacePreloader(), + LocationsDspacerest: buildLocationsDspacerestPreloader(), + LocationsDuracloud: buildLocationsDuracloudPreloader(), + LocationsEvent: buildLocationsEventPreloader(), + LocationsFedora: buildLocationsFedoraPreloader(), + LocationsFile: buildLocationsFilePreloader(), + LocationsFixitylog: buildLocationsFixitylogPreloader(), + LocationsGPG: buildLocationsGPGPreloader(), + LocationsLocalfilesystem: buildLocationsLocalfilesystemPreloader(), + LocationsLocation: buildLocationsLocationPreloader(), + LocationsLocationReplicator: buildLocationsLocationReplicatorPreloader(), + LocationsLocationpipeline: buildLocationsLocationpipelinePreloader(), + LocationsLockssomatic: buildLocationsLockssomaticPreloader(), + LocationsNF: buildLocationsNFPreloader(), + LocationsOfflinereplicastaging: buildLocationsOfflinereplicastagingPreloader(), + LocationsPackage: buildLocationsPackagePreloader(), + LocationsPackageRelatedPackage: buildLocationsPackageRelatedPackagePreloader(), + LocationsPackagedownloadtask: buildLocationsPackagedownloadtaskPreloader(), + LocationsPackagedownloadtaskfile: buildLocationsPackagedownloadtaskfilePreloader(), + LocationsPipeline: buildLocationsPipelinePreloader(), + LocationsPipelinelocalf: buildLocationsPipelinelocalfPreloader(), + LocationsRclone: buildLocationsRclonePreloader(), + LocationsS3: buildLocationsS3Preloader(), + LocationsSpace: buildLocationsSpacePreloader(), + LocationsSwift: buildLocationsSwiftPreloader(), + TastypieApikey: buildTastypieApikeyPreloader(), + } +} + +var SelectThenLoad = getThenLoaders[*dialect.SelectQuery]() + +type thenLoaders[Q orm.Loadable] struct { + AuthGroup authGroupThenLoader[Q] + AuthGroupPermission authGroupPermissionThenLoader[Q] + AuthPermission authPermissionThenLoader[Q] + AuthUser authUserThenLoader[Q] + AuthUserGroup authUserGroupThenLoader[Q] + AuthUserUserPermission authUserUserPermissionThenLoader[Q] + DjangoAdminLog djangoAdminLogThenLoader[Q] + DjangoContentType djangoContentTypeThenLoader[Q] + LocationsArchipelago locationsArchipelagoThenLoader[Q] + LocationsArkivum locationsArkivumThenLoader[Q] + LocationsDataverse locationsDataverseThenLoader[Q] + LocationsDspace locationsDspaceThenLoader[Q] + LocationsDspacerest locationsDspacerestThenLoader[Q] + LocationsDuracloud locationsDuracloudThenLoader[Q] + LocationsEvent locationsEventThenLoader[Q] + LocationsFedora locationsFedoraThenLoader[Q] + LocationsFile locationsFileThenLoader[Q] + LocationsFixitylog locationsFixitylogThenLoader[Q] + LocationsGPG locationsGPGThenLoader[Q] + LocationsLocalfilesystem locationsLocalfilesystemThenLoader[Q] + LocationsLocation locationsLocationThenLoader[Q] + LocationsLocationReplicator locationsLocationReplicatorThenLoader[Q] + LocationsLocationpipeline locationsLocationpipelineThenLoader[Q] + LocationsLockssomatic locationsLockssomaticThenLoader[Q] + LocationsNF locationsNFThenLoader[Q] + LocationsOfflinereplicastaging locationsOfflinereplicastagingThenLoader[Q] + LocationsPackage locationsPackageThenLoader[Q] + LocationsPackageRelatedPackage locationsPackageRelatedPackageThenLoader[Q] + LocationsPackagedownloadtask locationsPackagedownloadtaskThenLoader[Q] + LocationsPackagedownloadtaskfile locationsPackagedownloadtaskfileThenLoader[Q] + LocationsPipeline locationsPipelineThenLoader[Q] + LocationsPipelinelocalf locationsPipelinelocalfThenLoader[Q] + LocationsRclone locationsRcloneThenLoader[Q] + LocationsS3 locationsS3ThenLoader[Q] + LocationsSpace locationsSpaceThenLoader[Q] + LocationsSwift locationsSwiftThenLoader[Q] + TastypieApikey tastypieApikeyThenLoader[Q] +} + +func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] { + return thenLoaders[Q]{ + AuthGroup: buildAuthGroupThenLoader[Q](), + AuthGroupPermission: buildAuthGroupPermissionThenLoader[Q](), + AuthPermission: buildAuthPermissionThenLoader[Q](), + AuthUser: buildAuthUserThenLoader[Q](), + AuthUserGroup: buildAuthUserGroupThenLoader[Q](), + AuthUserUserPermission: buildAuthUserUserPermissionThenLoader[Q](), + DjangoAdminLog: buildDjangoAdminLogThenLoader[Q](), + DjangoContentType: buildDjangoContentTypeThenLoader[Q](), + LocationsArchipelago: buildLocationsArchipelagoThenLoader[Q](), + LocationsArkivum: buildLocationsArkivumThenLoader[Q](), + LocationsDataverse: buildLocationsDataverseThenLoader[Q](), + LocationsDspace: buildLocationsDspaceThenLoader[Q](), + LocationsDspacerest: buildLocationsDspacerestThenLoader[Q](), + LocationsDuracloud: buildLocationsDuracloudThenLoader[Q](), + LocationsEvent: buildLocationsEventThenLoader[Q](), + LocationsFedora: buildLocationsFedoraThenLoader[Q](), + LocationsFile: buildLocationsFileThenLoader[Q](), + LocationsFixitylog: buildLocationsFixitylogThenLoader[Q](), + LocationsGPG: buildLocationsGPGThenLoader[Q](), + LocationsLocalfilesystem: buildLocationsLocalfilesystemThenLoader[Q](), + LocationsLocation: buildLocationsLocationThenLoader[Q](), + LocationsLocationReplicator: buildLocationsLocationReplicatorThenLoader[Q](), + LocationsLocationpipeline: buildLocationsLocationpipelineThenLoader[Q](), + LocationsLockssomatic: buildLocationsLockssomaticThenLoader[Q](), + LocationsNF: buildLocationsNFThenLoader[Q](), + LocationsOfflinereplicastaging: buildLocationsOfflinereplicastagingThenLoader[Q](), + LocationsPackage: buildLocationsPackageThenLoader[Q](), + LocationsPackageRelatedPackage: buildLocationsPackageRelatedPackageThenLoader[Q](), + LocationsPackagedownloadtask: buildLocationsPackagedownloadtaskThenLoader[Q](), + LocationsPackagedownloadtaskfile: buildLocationsPackagedownloadtaskfileThenLoader[Q](), + LocationsPipeline: buildLocationsPipelineThenLoader[Q](), + LocationsPipelinelocalf: buildLocationsPipelinelocalfThenLoader[Q](), + LocationsRclone: buildLocationsRcloneThenLoader[Q](), + LocationsS3: buildLocationsS3ThenLoader[Q](), + LocationsSpace: buildLocationsSpaceThenLoader[Q](), + LocationsSwift: buildLocationsSwiftThenLoader[Q](), + TastypieApikey: buildTastypieApikeyThenLoader[Q](), + } +} + +func thenLoadBuilder[Q orm.Loadable, T any](name string, f func(context.Context, bob.Executor, T, ...bob.Mod[*dialect.SelectQuery]) error) func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] { + return func(queryMods ...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] { + return func(ctx context.Context, exec bob.Executor, retrieved any) error { + loader, isLoader := retrieved.(T) + if !isLoader { + return fmt.Errorf("object %T cannot load %q", retrieved, name) + } + + err := f(ctx, exec, loader, queryMods...) + + // Don't cause an issue due to missing relationships + if errors.Is(err, sql.ErrNoRows) { + return nil + } + + return err + } + } +} diff --git a/database/storage_service/models/bob_types.bob_test.go b/database/storage_service/models/bob_types.bob_test.go new file mode 100644 index 0000000..5dec749 --- /dev/null +++ b/database/storage_service/models/bob_types.bob_test.go @@ -0,0 +1,141 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import "github.com/stephenafamo/bob" + +// Set the testDB to enable tests that use the database +var testDB bob.Transactor[bob.Tx] + +// Make sure the type AdministrationSetting runs hooks after queries +var _ bob.HookableType = &AdministrationSetting{} + +// Make sure the type AuthGroup runs hooks after queries +var _ bob.HookableType = &AuthGroup{} + +// Make sure the type AuthGroupPermission runs hooks after queries +var _ bob.HookableType = &AuthGroupPermission{} + +// Make sure the type AuthPermission runs hooks after queries +var _ bob.HookableType = &AuthPermission{} + +// Make sure the type AuthUser runs hooks after queries +var _ bob.HookableType = &AuthUser{} + +// Make sure the type AuthUserGroup runs hooks after queries +var _ bob.HookableType = &AuthUserGroup{} + +// Make sure the type AuthUserUserPermission runs hooks after queries +var _ bob.HookableType = &AuthUserUserPermission{} + +// Make sure the type DjangoAdminLog runs hooks after queries +var _ bob.HookableType = &DjangoAdminLog{} + +// Make sure the type DjangoContentType runs hooks after queries +var _ bob.HookableType = &DjangoContentType{} + +// Make sure the type DjangoMigration runs hooks after queries +var _ bob.HookableType = &DjangoMigration{} + +// Make sure the type DjangoSession runs hooks after queries +var _ bob.HookableType = &DjangoSession{} + +// Make sure the type DjangoSite runs hooks after queries +var _ bob.HookableType = &DjangoSite{} + +// Make sure the type LocationsArchipelago runs hooks after queries +var _ bob.HookableType = &LocationsArchipelago{} + +// Make sure the type LocationsArkivum runs hooks after queries +var _ bob.HookableType = &LocationsArkivum{} + +// Make sure the type LocationsAsync runs hooks after queries +var _ bob.HookableType = &LocationsAsync{} + +// Make sure the type LocationsCallback runs hooks after queries +var _ bob.HookableType = &LocationsCallback{} + +// Make sure the type LocationsDataverse runs hooks after queries +var _ bob.HookableType = &LocationsDataverse{} + +// Make sure the type LocationsDspace runs hooks after queries +var _ bob.HookableType = &LocationsDspace{} + +// Make sure the type LocationsDspacerest runs hooks after queries +var _ bob.HookableType = &LocationsDspacerest{} + +// Make sure the type LocationsDuracloud runs hooks after queries +var _ bob.HookableType = &LocationsDuracloud{} + +// Make sure the type LocationsEvent runs hooks after queries +var _ bob.HookableType = &LocationsEvent{} + +// Make sure the type LocationsFedora runs hooks after queries +var _ bob.HookableType = &LocationsFedora{} + +// Make sure the type LocationsFile runs hooks after queries +var _ bob.HookableType = &LocationsFile{} + +// Make sure the type LocationsFixitylog runs hooks after queries +var _ bob.HookableType = &LocationsFixitylog{} + +// Make sure the type LocationsGPG runs hooks after queries +var _ bob.HookableType = &LocationsGPG{} + +// Make sure the type LocationsLocalfilesystem runs hooks after queries +var _ bob.HookableType = &LocationsLocalfilesystem{} + +// Make sure the type LocationsLocation runs hooks after queries +var _ bob.HookableType = &LocationsLocation{} + +// Make sure the type LocationsLocationReplicator runs hooks after queries +var _ bob.HookableType = &LocationsLocationReplicator{} + +// Make sure the type LocationsLocationpipeline runs hooks after queries +var _ bob.HookableType = &LocationsLocationpipeline{} + +// Make sure the type LocationsLockssomatic runs hooks after queries +var _ bob.HookableType = &LocationsLockssomatic{} + +// Make sure the type LocationsNF runs hooks after queries +var _ bob.HookableType = &LocationsNF{} + +// Make sure the type LocationsOfflinereplicastaging runs hooks after queries +var _ bob.HookableType = &LocationsOfflinereplicastaging{} + +// Make sure the type LocationsPackage runs hooks after queries +var _ bob.HookableType = &LocationsPackage{} + +// Make sure the type LocationsPackageRelatedPackage runs hooks after queries +var _ bob.HookableType = &LocationsPackageRelatedPackage{} + +// Make sure the type LocationsPackagedownloadtask runs hooks after queries +var _ bob.HookableType = &LocationsPackagedownloadtask{} + +// Make sure the type LocationsPackagedownloadtaskfile runs hooks after queries +var _ bob.HookableType = &LocationsPackagedownloadtaskfile{} + +// Make sure the type LocationsPipeline runs hooks after queries +var _ bob.HookableType = &LocationsPipeline{} + +// Make sure the type LocationsPipelinelocalf runs hooks after queries +var _ bob.HookableType = &LocationsPipelinelocalf{} + +// Make sure the type LocationsRclone runs hooks after queries +var _ bob.HookableType = &LocationsRclone{} + +// Make sure the type LocationsS3 runs hooks after queries +var _ bob.HookableType = &LocationsS3{} + +// Make sure the type LocationsSpace runs hooks after queries +var _ bob.HookableType = &LocationsSpace{} + +// Make sure the type LocationsSwift runs hooks after queries +var _ bob.HookableType = &LocationsSwift{} + +// Make sure the type TastypieApiaccess runs hooks after queries +var _ bob.HookableType = &TastypieApiaccess{} + +// Make sure the type TastypieApikey runs hooks after queries +var _ bob.HookableType = &TastypieApikey{} diff --git a/database/storage_service/models/bob_where.bob.go b/database/storage_service/models/bob_where.bob.go new file mode 100644 index 0000000..aa26707 --- /dev/null +++ b/database/storage_service/models/bob_where.bob.go @@ -0,0 +1,156 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "github.com/stephenafamo/bob/clause" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" +) + +var ( + SelectWhere = Where[*dialect.SelectQuery]() + UpdateWhere = Where[*dialect.UpdateQuery]() + DeleteWhere = Where[*dialect.DeleteQuery]() + OnConflictWhere = Where[*clause.ConflictClause]() // Used in ON CONFLICT DO UPDATE +) + +func Where[Q mysql.Filterable]() struct { + AdministrationSettings administrationSettingWhere[Q] + AuthGroups authGroupWhere[Q] + AuthGroupPermissions authGroupPermissionWhere[Q] + AuthPermissions authPermissionWhere[Q] + AuthUsers authUserWhere[Q] + AuthUserGroups authUserGroupWhere[Q] + AuthUserUserPermissions authUserUserPermissionWhere[Q] + DjangoAdminLogs djangoAdminLogWhere[Q] + DjangoContentTypes djangoContentTypeWhere[Q] + DjangoMigrations djangoMigrationWhere[Q] + DjangoSessions djangoSessionWhere[Q] + DjangoSites djangoSiteWhere[Q] + LocationsArchipelagos locationsArchipelagoWhere[Q] + LocationsArkivums locationsArkivumWhere[Q] + LocationsAsyncs locationsAsyncWhere[Q] + LocationsCallbacks locationsCallbackWhere[Q] + LocationsDataverses locationsDataverseWhere[Q] + LocationsDspaces locationsDspaceWhere[Q] + LocationsDspacerests locationsDspacerestWhere[Q] + LocationsDuraclouds locationsDuracloudWhere[Q] + LocationsEvents locationsEventWhere[Q] + LocationsFedoras locationsFedoraWhere[Q] + LocationsFiles locationsFileWhere[Q] + LocationsFixitylogs locationsFixitylogWhere[Q] + LocationsGPGS locationsGPGWhere[Q] + LocationsLocalfilesystems locationsLocalfilesystemWhere[Q] + LocationsLocations locationsLocationWhere[Q] + LocationsLocationReplicators locationsLocationReplicatorWhere[Q] + LocationsLocationpipelines locationsLocationpipelineWhere[Q] + LocationsLockssomatics locationsLockssomaticWhere[Q] + LocationsNFS locationsNFWhere[Q] + LocationsOfflinereplicastagings locationsOfflinereplicastagingWhere[Q] + LocationsPackages locationsPackageWhere[Q] + LocationsPackageRelatedPackages locationsPackageRelatedPackageWhere[Q] + LocationsPackagedownloadtasks locationsPackagedownloadtaskWhere[Q] + LocationsPackagedownloadtaskfiles locationsPackagedownloadtaskfileWhere[Q] + LocationsPipelines locationsPipelineWhere[Q] + LocationsPipelinelocalfs locationsPipelinelocalfWhere[Q] + LocationsRclones locationsRcloneWhere[Q] + LocationsS3S locationsS3Where[Q] + LocationsSpaces locationsSpaceWhere[Q] + LocationsSwifts locationsSwiftWhere[Q] + TastypieApiaccesses tastypieApiaccessWhere[Q] + TastypieApikeys tastypieApikeyWhere[Q] +} { + return struct { + AdministrationSettings administrationSettingWhere[Q] + AuthGroups authGroupWhere[Q] + AuthGroupPermissions authGroupPermissionWhere[Q] + AuthPermissions authPermissionWhere[Q] + AuthUsers authUserWhere[Q] + AuthUserGroups authUserGroupWhere[Q] + AuthUserUserPermissions authUserUserPermissionWhere[Q] + DjangoAdminLogs djangoAdminLogWhere[Q] + DjangoContentTypes djangoContentTypeWhere[Q] + DjangoMigrations djangoMigrationWhere[Q] + DjangoSessions djangoSessionWhere[Q] + DjangoSites djangoSiteWhere[Q] + LocationsArchipelagos locationsArchipelagoWhere[Q] + LocationsArkivums locationsArkivumWhere[Q] + LocationsAsyncs locationsAsyncWhere[Q] + LocationsCallbacks locationsCallbackWhere[Q] + LocationsDataverses locationsDataverseWhere[Q] + LocationsDspaces locationsDspaceWhere[Q] + LocationsDspacerests locationsDspacerestWhere[Q] + LocationsDuraclouds locationsDuracloudWhere[Q] + LocationsEvents locationsEventWhere[Q] + LocationsFedoras locationsFedoraWhere[Q] + LocationsFiles locationsFileWhere[Q] + LocationsFixitylogs locationsFixitylogWhere[Q] + LocationsGPGS locationsGPGWhere[Q] + LocationsLocalfilesystems locationsLocalfilesystemWhere[Q] + LocationsLocations locationsLocationWhere[Q] + LocationsLocationReplicators locationsLocationReplicatorWhere[Q] + LocationsLocationpipelines locationsLocationpipelineWhere[Q] + LocationsLockssomatics locationsLockssomaticWhere[Q] + LocationsNFS locationsNFWhere[Q] + LocationsOfflinereplicastagings locationsOfflinereplicastagingWhere[Q] + LocationsPackages locationsPackageWhere[Q] + LocationsPackageRelatedPackages locationsPackageRelatedPackageWhere[Q] + LocationsPackagedownloadtasks locationsPackagedownloadtaskWhere[Q] + LocationsPackagedownloadtaskfiles locationsPackagedownloadtaskfileWhere[Q] + LocationsPipelines locationsPipelineWhere[Q] + LocationsPipelinelocalfs locationsPipelinelocalfWhere[Q] + LocationsRclones locationsRcloneWhere[Q] + LocationsS3S locationsS3Where[Q] + LocationsSpaces locationsSpaceWhere[Q] + LocationsSwifts locationsSwiftWhere[Q] + TastypieApiaccesses tastypieApiaccessWhere[Q] + TastypieApikeys tastypieApikeyWhere[Q] + }{ + AdministrationSettings: buildAdministrationSettingWhere[Q](AdministrationSettings.Columns), + AuthGroups: buildAuthGroupWhere[Q](AuthGroups.Columns), + AuthGroupPermissions: buildAuthGroupPermissionWhere[Q](AuthGroupPermissions.Columns), + AuthPermissions: buildAuthPermissionWhere[Q](AuthPermissions.Columns), + AuthUsers: buildAuthUserWhere[Q](AuthUsers.Columns), + AuthUserGroups: buildAuthUserGroupWhere[Q](AuthUserGroups.Columns), + AuthUserUserPermissions: buildAuthUserUserPermissionWhere[Q](AuthUserUserPermissions.Columns), + DjangoAdminLogs: buildDjangoAdminLogWhere[Q](DjangoAdminLogs.Columns), + DjangoContentTypes: buildDjangoContentTypeWhere[Q](DjangoContentTypes.Columns), + DjangoMigrations: buildDjangoMigrationWhere[Q](DjangoMigrations.Columns), + DjangoSessions: buildDjangoSessionWhere[Q](DjangoSessions.Columns), + DjangoSites: buildDjangoSiteWhere[Q](DjangoSites.Columns), + LocationsArchipelagos: buildLocationsArchipelagoWhere[Q](LocationsArchipelagos.Columns), + LocationsArkivums: buildLocationsArkivumWhere[Q](LocationsArkivums.Columns), + LocationsAsyncs: buildLocationsAsyncWhere[Q](LocationsAsyncs.Columns), + LocationsCallbacks: buildLocationsCallbackWhere[Q](LocationsCallbacks.Columns), + LocationsDataverses: buildLocationsDataverseWhere[Q](LocationsDataverses.Columns), + LocationsDspaces: buildLocationsDspaceWhere[Q](LocationsDspaces.Columns), + LocationsDspacerests: buildLocationsDspacerestWhere[Q](LocationsDspacerests.Columns), + LocationsDuraclouds: buildLocationsDuracloudWhere[Q](LocationsDuraclouds.Columns), + LocationsEvents: buildLocationsEventWhere[Q](LocationsEvents.Columns), + LocationsFedoras: buildLocationsFedoraWhere[Q](LocationsFedoras.Columns), + LocationsFiles: buildLocationsFileWhere[Q](LocationsFiles.Columns), + LocationsFixitylogs: buildLocationsFixitylogWhere[Q](LocationsFixitylogs.Columns), + LocationsGPGS: buildLocationsGPGWhere[Q](LocationsGPGS.Columns), + LocationsLocalfilesystems: buildLocationsLocalfilesystemWhere[Q](LocationsLocalfilesystems.Columns), + LocationsLocations: buildLocationsLocationWhere[Q](LocationsLocations.Columns), + LocationsLocationReplicators: buildLocationsLocationReplicatorWhere[Q](LocationsLocationReplicators.Columns), + LocationsLocationpipelines: buildLocationsLocationpipelineWhere[Q](LocationsLocationpipelines.Columns), + LocationsLockssomatics: buildLocationsLockssomaticWhere[Q](LocationsLockssomatics.Columns), + LocationsNFS: buildLocationsNFWhere[Q](LocationsNFS.Columns), + LocationsOfflinereplicastagings: buildLocationsOfflinereplicastagingWhere[Q](LocationsOfflinereplicastagings.Columns), + LocationsPackages: buildLocationsPackageWhere[Q](LocationsPackages.Columns), + LocationsPackageRelatedPackages: buildLocationsPackageRelatedPackageWhere[Q](LocationsPackageRelatedPackages.Columns), + LocationsPackagedownloadtasks: buildLocationsPackagedownloadtaskWhere[Q](LocationsPackagedownloadtasks.Columns), + LocationsPackagedownloadtaskfiles: buildLocationsPackagedownloadtaskfileWhere[Q](LocationsPackagedownloadtaskfiles.Columns), + LocationsPipelines: buildLocationsPipelineWhere[Q](LocationsPipelines.Columns), + LocationsPipelinelocalfs: buildLocationsPipelinelocalfWhere[Q](LocationsPipelinelocalfs.Columns), + LocationsRclones: buildLocationsRcloneWhere[Q](LocationsRclones.Columns), + LocationsS3S: buildLocationsS3Where[Q](LocationsS3S.Columns), + LocationsSpaces: buildLocationsSpaceWhere[Q](LocationsSpaces.Columns), + LocationsSwifts: buildLocationsSwiftWhere[Q](LocationsSwifts.Columns), + TastypieApiaccesses: buildTastypieApiaccessWhere[Q](TastypieApiaccesses.Columns), + TastypieApikeys: buildTastypieApikeyWhere[Q](TastypieApikeys.Columns), + } +} diff --git a/database/storage_service/models/django_admin_log.bob.go b/database/storage_service/models/django_admin_log.bob.go new file mode 100644 index 0000000..7f6569c --- /dev/null +++ b/database/storage_service/models/django_admin_log.bob.go @@ -0,0 +1,913 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// DjangoAdminLog is an object representing the database table. +type DjangoAdminLog struct { + ID int32 `db:"id,pk,autoincr" ` + ActionTime time.Time `db:"action_time" ` + ObjectID null.Val[string] `db:"object_id" ` + ObjectRepr string `db:"object_repr" ` + ActionFlag uint16 `db:"action_flag" ` + ChangeMessage string `db:"change_message" ` + ContentTypeID null.Val[int32] `db:"content_type_id" ` + UserID int32 `db:"user_id" ` + + R djangoAdminLogR `db:"-" ` +} + +// DjangoAdminLogSlice is an alias for a slice of pointers to DjangoAdminLog. +// This should almost always be used instead of []*DjangoAdminLog. +type DjangoAdminLogSlice []*DjangoAdminLog + +// DjangoAdminLogs contains methods to work with the django_admin_log table +var DjangoAdminLogs = mysql.NewTablex[*DjangoAdminLog, DjangoAdminLogSlice, *DjangoAdminLogSetter]("django_admin_log", buildDjangoAdminLogColumns("django_admin_log"), []string{"id"}) + +// DjangoAdminLogsQuery is a query on the django_admin_log table +type DjangoAdminLogsQuery = *mysql.ViewQuery[*DjangoAdminLog, DjangoAdminLogSlice] + +// djangoAdminLogR is where relationships are stored. +type djangoAdminLogR struct { + ContentTypeDjangoContentType *DjangoContentType // django_admin_log_content_type_id_c4bce8eb_fk_django_co + UserAuthUser *AuthUser // django_admin_log_user_id_c564eba6_fk_auth_user_id +} + +func buildDjangoAdminLogColumns(alias string) djangoAdminLogColumns { + return djangoAdminLogColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "action_time", "object_id", "object_repr", "action_flag", "change_message", "content_type_id", "user_id", + ).WithParent("django_admin_log"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + ActionTime: mysql.Quote(alias, "action_time"), + ObjectID: mysql.Quote(alias, "object_id"), + ObjectRepr: mysql.Quote(alias, "object_repr"), + ActionFlag: mysql.Quote(alias, "action_flag"), + ChangeMessage: mysql.Quote(alias, "change_message"), + ContentTypeID: mysql.Quote(alias, "content_type_id"), + UserID: mysql.Quote(alias, "user_id"), + } +} + +type djangoAdminLogColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + ActionTime mysql.Expression + ObjectID mysql.Expression + ObjectRepr mysql.Expression + ActionFlag mysql.Expression + ChangeMessage mysql.Expression + ContentTypeID mysql.Expression + UserID mysql.Expression +} + +func (c djangoAdminLogColumns) Alias() string { + return c.tableAlias +} + +func (djangoAdminLogColumns) AliasedAs(alias string) djangoAdminLogColumns { + return buildDjangoAdminLogColumns(alias) +} + +// DjangoAdminLogSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type DjangoAdminLogSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + ActionTime omit.Val[time.Time] `db:"action_time" ` + ObjectID omitnull.Val[string] `db:"object_id" ` + ObjectRepr omit.Val[string] `db:"object_repr" ` + ActionFlag omit.Val[uint16] `db:"action_flag" ` + ChangeMessage omit.Val[string] `db:"change_message" ` + ContentTypeID omitnull.Val[int32] `db:"content_type_id" ` + UserID omit.Val[int32] `db:"user_id" ` +} + +func (s DjangoAdminLogSetter) SetColumns() []string { + vals := make([]string, 0, 8) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.ActionTime.IsValue() { + vals = append(vals, "action_time") + } + if !s.ObjectID.IsUnset() { + vals = append(vals, "object_id") + } + if s.ObjectRepr.IsValue() { + vals = append(vals, "object_repr") + } + if s.ActionFlag.IsValue() { + vals = append(vals, "action_flag") + } + if s.ChangeMessage.IsValue() { + vals = append(vals, "change_message") + } + if !s.ContentTypeID.IsUnset() { + vals = append(vals, "content_type_id") + } + if s.UserID.IsValue() { + vals = append(vals, "user_id") + } + return vals +} + +func (s DjangoAdminLogSetter) Overwrite(t *DjangoAdminLog) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.ActionTime.IsValue() { + t.ActionTime = s.ActionTime.MustGet() + } + if !s.ObjectID.IsUnset() { + t.ObjectID = s.ObjectID.MustGetNull() + } + if s.ObjectRepr.IsValue() { + t.ObjectRepr = s.ObjectRepr.MustGet() + } + if s.ActionFlag.IsValue() { + t.ActionFlag = s.ActionFlag.MustGet() + } + if s.ChangeMessage.IsValue() { + t.ChangeMessage = s.ChangeMessage.MustGet() + } + if !s.ContentTypeID.IsUnset() { + t.ContentTypeID = s.ContentTypeID.MustGetNull() + } + if s.UserID.IsValue() { + t.UserID = s.UserID.MustGet() + } +} + +func (s *DjangoAdminLogSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoAdminLogs.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ActionTime.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ActionTime.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.ObjectID.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ObjectID.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ObjectRepr.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ObjectRepr.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ActionFlag.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ActionFlag.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ChangeMessage.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ChangeMessage.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.ContentTypeID.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ContentTypeID.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UserID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UserID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s DjangoAdminLogSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("django_admin_log")...) +} + +func (s DjangoAdminLogSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 8) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.ActionTime.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "action_time")...), + mysql.Arg(s.ActionTime), + }}) + } + + if !s.ObjectID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "object_id")...), + mysql.Arg(s.ObjectID), + }}) + } + + if s.ObjectRepr.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "object_repr")...), + mysql.Arg(s.ObjectRepr), + }}) + } + + if s.ActionFlag.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "action_flag")...), + mysql.Arg(s.ActionFlag), + }}) + } + + if s.ChangeMessage.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "change_message")...), + mysql.Arg(s.ChangeMessage), + }}) + } + + if !s.ContentTypeID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "content_type_id")...), + mysql.Arg(s.ContentTypeID), + }}) + } + + if s.UserID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "user_id")...), + mysql.Arg(s.UserID), + }}) + } + + return exprs +} + +// FindDjangoAdminLog retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindDjangoAdminLog(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*DjangoAdminLog, error) { + if len(cols) == 0 { + return DjangoAdminLogs.Query( + sm.Where(DjangoAdminLogs.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return DjangoAdminLogs.Query( + sm.Where(DjangoAdminLogs.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(DjangoAdminLogs.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// DjangoAdminLogExists checks the presence of a single record by primary key +func DjangoAdminLogExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return DjangoAdminLogs.Query( + sm.Where(DjangoAdminLogs.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after DjangoAdminLog is retrieved from the database +func (o *DjangoAdminLog) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoAdminLogs.AfterSelectHooks.RunHooks(ctx, exec, DjangoAdminLogSlice{o}) + case bob.QueryTypeInsert: + ctx, err = DjangoAdminLogs.AfterInsertHooks.RunHooks(ctx, exec, DjangoAdminLogSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = DjangoAdminLogs.AfterUpdateHooks.RunHooks(ctx, exec, DjangoAdminLogSlice{o}) + case bob.QueryTypeDelete: + ctx, err = DjangoAdminLogs.AfterDeleteHooks.RunHooks(ctx, exec, DjangoAdminLogSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the DjangoAdminLog +func (o *DjangoAdminLog) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *DjangoAdminLog) pkEQ() dialect.Expression { + return mysql.Quote("django_admin_log", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the DjangoAdminLog +func (o *DjangoAdminLog) Update(ctx context.Context, exec bob.Executor, s *DjangoAdminLogSetter) error { + _, err := DjangoAdminLogs.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single DjangoAdminLog record with an executor +func (o *DjangoAdminLog) Delete(ctx context.Context, exec bob.Executor) error { + _, err := DjangoAdminLogs.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the DjangoAdminLog using the executor +func (o *DjangoAdminLog) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := DjangoAdminLogs.Query( + sm.Where(DjangoAdminLogs.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after DjangoAdminLogSlice is retrieved from the database +func (o DjangoAdminLogSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoAdminLogs.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = DjangoAdminLogs.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = DjangoAdminLogs.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = DjangoAdminLogs.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o DjangoAdminLogSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("django_admin_log", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o DjangoAdminLogSlice) copyMatchingRows(from ...*DjangoAdminLog) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o DjangoAdminLogSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoAdminLogs.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoAdminLog: + o.copyMatchingRows(retrieved) + case []*DjangoAdminLog: + o.copyMatchingRows(retrieved...) + case DjangoAdminLogSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoAdminLog or a slice of DjangoAdminLog + // then run the AfterUpdateHooks on the slice + _, err = DjangoAdminLogs.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o DjangoAdminLogSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoAdminLogs.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoAdminLog: + o.copyMatchingRows(retrieved) + case []*DjangoAdminLog: + o.copyMatchingRows(retrieved...) + case DjangoAdminLogSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoAdminLog or a slice of DjangoAdminLog + // then run the AfterDeleteHooks on the slice + _, err = DjangoAdminLogs.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o DjangoAdminLogSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals DjangoAdminLogSetter) error { + _, err := DjangoAdminLogs.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o DjangoAdminLogSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := DjangoAdminLogs.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o DjangoAdminLogSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := DjangoAdminLogs.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// ContentTypeDjangoContentType starts a query for related objects on django_content_type +func (o *DjangoAdminLog) ContentTypeDjangoContentType(mods ...bob.Mod[*dialect.SelectQuery]) DjangoContentTypesQuery { + return DjangoContentTypes.Query(append(mods, + sm.Where(DjangoContentTypes.Columns.ID.EQ(mysql.Arg(o.ContentTypeID))), + )...) +} + +func (os DjangoAdminLogSlice) ContentTypeDjangoContentType(mods ...bob.Mod[*dialect.SelectQuery]) DjangoContentTypesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ContentTypeID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return DjangoContentTypes.Query(append(mods, + sm.Where(mysql.Group(DjangoContentTypes.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// UserAuthUser starts a query for related objects on auth_user +func (o *DjangoAdminLog) UserAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + return AuthUsers.Query(append(mods, + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(o.UserID))), + )...) +} + +func (os DjangoAdminLogSlice) UserAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UserID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUsers.Query(append(mods, + sm.Where(mysql.Group(AuthUsers.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func attachDjangoAdminLogContentTypeDjangoContentType0(ctx context.Context, exec bob.Executor, count int, djangoAdminLog0 *DjangoAdminLog, djangoContentType1 *DjangoContentType) (*DjangoAdminLog, error) { + setter := &DjangoAdminLogSetter{ + ContentTypeID: omitnull.From(djangoContentType1.ID), + } + + err := djangoAdminLog0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachDjangoAdminLogContentTypeDjangoContentType0: %w", err) + } + + return djangoAdminLog0, nil +} + +func (djangoAdminLog0 *DjangoAdminLog) InsertContentTypeDjangoContentType(ctx context.Context, exec bob.Executor, related *DjangoContentTypeSetter) error { + var err error + + djangoContentType1, err := DjangoContentTypes.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachDjangoAdminLogContentTypeDjangoContentType0(ctx, exec, 1, djangoAdminLog0, djangoContentType1) + if err != nil { + return err + } + + djangoAdminLog0.R.ContentTypeDjangoContentType = djangoContentType1 + + djangoContentType1.R.ContentTypeDjangoAdminLogs = append(djangoContentType1.R.ContentTypeDjangoAdminLogs, djangoAdminLog0) + + return nil +} + +func (djangoAdminLog0 *DjangoAdminLog) AttachContentTypeDjangoContentType(ctx context.Context, exec bob.Executor, djangoContentType1 *DjangoContentType) error { + var err error + + _, err = attachDjangoAdminLogContentTypeDjangoContentType0(ctx, exec, 1, djangoAdminLog0, djangoContentType1) + if err != nil { + return err + } + + djangoAdminLog0.R.ContentTypeDjangoContentType = djangoContentType1 + + djangoContentType1.R.ContentTypeDjangoAdminLogs = append(djangoContentType1.R.ContentTypeDjangoAdminLogs, djangoAdminLog0) + + return nil +} + +func attachDjangoAdminLogUserAuthUser0(ctx context.Context, exec bob.Executor, count int, djangoAdminLog0 *DjangoAdminLog, authUser1 *AuthUser) (*DjangoAdminLog, error) { + setter := &DjangoAdminLogSetter{ + UserID: omit.From(authUser1.ID), + } + + err := djangoAdminLog0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachDjangoAdminLogUserAuthUser0: %w", err) + } + + return djangoAdminLog0, nil +} + +func (djangoAdminLog0 *DjangoAdminLog) InsertUserAuthUser(ctx context.Context, exec bob.Executor, related *AuthUserSetter) error { + var err error + + authUser1, err := AuthUsers.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachDjangoAdminLogUserAuthUser0(ctx, exec, 1, djangoAdminLog0, authUser1) + if err != nil { + return err + } + + djangoAdminLog0.R.UserAuthUser = authUser1 + + authUser1.R.UserDjangoAdminLogs = append(authUser1.R.UserDjangoAdminLogs, djangoAdminLog0) + + return nil +} + +func (djangoAdminLog0 *DjangoAdminLog) AttachUserAuthUser(ctx context.Context, exec bob.Executor, authUser1 *AuthUser) error { + var err error + + _, err = attachDjangoAdminLogUserAuthUser0(ctx, exec, 1, djangoAdminLog0, authUser1) + if err != nil { + return err + } + + djangoAdminLog0.R.UserAuthUser = authUser1 + + authUser1.R.UserDjangoAdminLogs = append(authUser1.R.UserDjangoAdminLogs, djangoAdminLog0) + + return nil +} + +type djangoAdminLogWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + ActionTime mysql.WhereMod[Q, time.Time] + ObjectID mysql.WhereNullMod[Q, string] + ObjectRepr mysql.WhereMod[Q, string] + ActionFlag mysql.WhereMod[Q, uint16] + ChangeMessage mysql.WhereMod[Q, string] + ContentTypeID mysql.WhereNullMod[Q, int32] + UserID mysql.WhereMod[Q, int32] +} + +func (djangoAdminLogWhere[Q]) AliasedAs(alias string) djangoAdminLogWhere[Q] { + return buildDjangoAdminLogWhere[Q](buildDjangoAdminLogColumns(alias)) +} + +func buildDjangoAdminLogWhere[Q mysql.Filterable](cols djangoAdminLogColumns) djangoAdminLogWhere[Q] { + return djangoAdminLogWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + ActionTime: mysql.Where[Q, time.Time](cols.ActionTime), + ObjectID: mysql.WhereNull[Q, string](cols.ObjectID), + ObjectRepr: mysql.Where[Q, string](cols.ObjectRepr), + ActionFlag: mysql.Where[Q, uint16](cols.ActionFlag), + ChangeMessage: mysql.Where[Q, string](cols.ChangeMessage), + ContentTypeID: mysql.WhereNull[Q, int32](cols.ContentTypeID), + UserID: mysql.Where[Q, int32](cols.UserID), + } +} + +func (o *DjangoAdminLog) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "ContentTypeDjangoContentType": + rel, ok := retrieved.(*DjangoContentType) + if !ok { + return fmt.Errorf("djangoAdminLog cannot load %T as %q", retrieved, name) + } + + o.R.ContentTypeDjangoContentType = rel + + if rel != nil { + rel.R.ContentTypeDjangoAdminLogs = DjangoAdminLogSlice{o} + } + return nil + case "UserAuthUser": + rel, ok := retrieved.(*AuthUser) + if !ok { + return fmt.Errorf("djangoAdminLog cannot load %T as %q", retrieved, name) + } + + o.R.UserAuthUser = rel + + if rel != nil { + rel.R.UserDjangoAdminLogs = DjangoAdminLogSlice{o} + } + return nil + default: + return fmt.Errorf("djangoAdminLog has no relationship %q", name) + } +} + +type djangoAdminLogPreloader struct { + ContentTypeDjangoContentType func(...mysql.PreloadOption) mysql.Preloader + UserAuthUser func(...mysql.PreloadOption) mysql.Preloader +} + +func buildDjangoAdminLogPreloader() djangoAdminLogPreloader { + return djangoAdminLogPreloader{ + ContentTypeDjangoContentType: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*DjangoContentType, DjangoContentTypeSlice](mysql.PreloadRel{ + Name: "ContentTypeDjangoContentType", + Sides: []mysql.PreloadSide{ + { + From: DjangoAdminLogs, + To: DjangoContentTypes, + FromColumns: []string{"content_type_id"}, + ToColumns: []string{"id"}, + }, + }, + }, DjangoContentTypes.Columns.Names(), opts...) + }, + UserAuthUser: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthUser, AuthUserSlice](mysql.PreloadRel{ + Name: "UserAuthUser", + Sides: []mysql.PreloadSide{ + { + From: DjangoAdminLogs, + To: AuthUsers, + FromColumns: []string{"user_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthUsers.Columns.Names(), opts...) + }, + } +} + +type djangoAdminLogThenLoader[Q orm.Loadable] struct { + ContentTypeDjangoContentType func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + UserAuthUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildDjangoAdminLogThenLoader[Q orm.Loadable]() djangoAdminLogThenLoader[Q] { + type ContentTypeDjangoContentTypeLoadInterface interface { + LoadContentTypeDjangoContentType(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type UserAuthUserLoadInterface interface { + LoadUserAuthUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return djangoAdminLogThenLoader[Q]{ + ContentTypeDjangoContentType: thenLoadBuilder[Q]( + "ContentTypeDjangoContentType", + func(ctx context.Context, exec bob.Executor, retrieved ContentTypeDjangoContentTypeLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadContentTypeDjangoContentType(ctx, exec, mods...) + }, + ), + UserAuthUser: thenLoadBuilder[Q]( + "UserAuthUser", + func(ctx context.Context, exec bob.Executor, retrieved UserAuthUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUserAuthUser(ctx, exec, mods...) + }, + ), + } +} + +// LoadContentTypeDjangoContentType loads the djangoAdminLog's ContentTypeDjangoContentType into the .R struct +func (o *DjangoAdminLog) LoadContentTypeDjangoContentType(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ContentTypeDjangoContentType = nil + + related, err := o.ContentTypeDjangoContentType(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.ContentTypeDjangoAdminLogs = DjangoAdminLogSlice{o} + + o.R.ContentTypeDjangoContentType = related + return nil +} + +// LoadContentTypeDjangoContentType loads the djangoAdminLog's ContentTypeDjangoContentType into the .R struct +func (os DjangoAdminLogSlice) LoadContentTypeDjangoContentType(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + djangoContentTypes, err := os.ContentTypeDjangoContentType(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range djangoContentTypes { + if !o.ContentTypeID.IsValue() { + continue + } + + if !(o.ContentTypeID.IsValue() && o.ContentTypeID.MustGet() == rel.ID) { + continue + } + + rel.R.ContentTypeDjangoAdminLogs = append(rel.R.ContentTypeDjangoAdminLogs, o) + + o.R.ContentTypeDjangoContentType = rel + break + } + } + + return nil +} + +// LoadUserAuthUser loads the djangoAdminLog's UserAuthUser into the .R struct +func (o *DjangoAdminLog) LoadUserAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UserAuthUser = nil + + related, err := o.UserAuthUser(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.UserDjangoAdminLogs = DjangoAdminLogSlice{o} + + o.R.UserAuthUser = related + return nil +} + +// LoadUserAuthUser loads the djangoAdminLog's UserAuthUser into the .R struct +func (os DjangoAdminLogSlice) LoadUserAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUsers, err := os.UserAuthUser(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUsers { + + if !(o.UserID == rel.ID) { + continue + } + + rel.R.UserDjangoAdminLogs = append(rel.R.UserDjangoAdminLogs, o) + + o.R.UserAuthUser = rel + break + } + } + + return nil +} + +type djangoAdminLogJoins[Q dialect.Joinable] struct { + typ string + ContentTypeDjangoContentType modAs[Q, djangoContentTypeColumns] + UserAuthUser modAs[Q, authUserColumns] +} + +func (j djangoAdminLogJoins[Q]) aliasedAs(alias string) djangoAdminLogJoins[Q] { + return buildDjangoAdminLogJoins[Q](buildDjangoAdminLogColumns(alias), j.typ) +} + +func buildDjangoAdminLogJoins[Q dialect.Joinable](cols djangoAdminLogColumns, typ string) djangoAdminLogJoins[Q] { + return djangoAdminLogJoins[Q]{ + typ: typ, + ContentTypeDjangoContentType: modAs[Q, djangoContentTypeColumns]{ + c: DjangoContentTypes.Columns, + f: func(to djangoContentTypeColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, DjangoContentTypes.Name().As(to.Alias())).On( + to.ID.EQ(cols.ContentTypeID), + )) + } + + return mods + }, + }, + UserAuthUser: modAs[Q, authUserColumns]{ + c: AuthUsers.Columns, + f: func(to authUserColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUsers.Name().As(to.Alias())).On( + to.ID.EQ(cols.UserID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/django_content_type.bob.go b/database/storage_service/models/django_content_type.bob.go new file mode 100644 index 0000000..7e90346 --- /dev/null +++ b/database/storage_service/models/django_content_type.bob.go @@ -0,0 +1,823 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// DjangoContentType is an object representing the database table. +type DjangoContentType struct { + ID int32 `db:"id,pk,autoincr" ` + AppLabel string `db:"app_label" ` + Model string `db:"model" ` + + R djangoContentTypeR `db:"-" ` +} + +// DjangoContentTypeSlice is an alias for a slice of pointers to DjangoContentType. +// This should almost always be used instead of []*DjangoContentType. +type DjangoContentTypeSlice []*DjangoContentType + +// DjangoContentTypes contains methods to work with the django_content_type table +var DjangoContentTypes = mysql.NewTablex[*DjangoContentType, DjangoContentTypeSlice, *DjangoContentTypeSetter]("django_content_type", buildDjangoContentTypeColumns("django_content_type"), []string{"id"}, []string{"app_label", "model"}) + +// DjangoContentTypesQuery is a query on the django_content_type table +type DjangoContentTypesQuery = *mysql.ViewQuery[*DjangoContentType, DjangoContentTypeSlice] + +// djangoContentTypeR is where relationships are stored. +type djangoContentTypeR struct { + ContentTypeAuthPermissions AuthPermissionSlice // auth_permission_content_type_id_2f476e4b_fk_django_co + ContentTypeDjangoAdminLogs DjangoAdminLogSlice // django_admin_log_content_type_id_c4bce8eb_fk_django_co +} + +func buildDjangoContentTypeColumns(alias string) djangoContentTypeColumns { + return djangoContentTypeColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "app_label", "model", + ).WithParent("django_content_type"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + AppLabel: mysql.Quote(alias, "app_label"), + Model: mysql.Quote(alias, "model"), + } +} + +type djangoContentTypeColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + AppLabel mysql.Expression + Model mysql.Expression +} + +func (c djangoContentTypeColumns) Alias() string { + return c.tableAlias +} + +func (djangoContentTypeColumns) AliasedAs(alias string) djangoContentTypeColumns { + return buildDjangoContentTypeColumns(alias) +} + +// DjangoContentTypeSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type DjangoContentTypeSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + AppLabel omit.Val[string] `db:"app_label" ` + Model omit.Val[string] `db:"model" ` +} + +func (s DjangoContentTypeSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.AppLabel.IsValue() { + vals = append(vals, "app_label") + } + if s.Model.IsValue() { + vals = append(vals, "model") + } + return vals +} + +func (s DjangoContentTypeSetter) Overwrite(t *DjangoContentType) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.AppLabel.IsValue() { + t.AppLabel = s.AppLabel.MustGet() + } + if s.Model.IsValue() { + t.Model = s.Model.MustGet() + } +} + +func (s *DjangoContentTypeSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoContentTypes.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AppLabel.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AppLabel.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Model.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Model.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s DjangoContentTypeSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("django_content_type")...) +} + +func (s DjangoContentTypeSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.AppLabel.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "app_label")...), + mysql.Arg(s.AppLabel), + }}) + } + + if s.Model.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "model")...), + mysql.Arg(s.Model), + }}) + } + + return exprs +} + +// FindDjangoContentType retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindDjangoContentType(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*DjangoContentType, error) { + if len(cols) == 0 { + return DjangoContentTypes.Query( + sm.Where(DjangoContentTypes.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return DjangoContentTypes.Query( + sm.Where(DjangoContentTypes.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(DjangoContentTypes.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// DjangoContentTypeExists checks the presence of a single record by primary key +func DjangoContentTypeExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return DjangoContentTypes.Query( + sm.Where(DjangoContentTypes.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after DjangoContentType is retrieved from the database +func (o *DjangoContentType) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoContentTypes.AfterSelectHooks.RunHooks(ctx, exec, DjangoContentTypeSlice{o}) + case bob.QueryTypeInsert: + ctx, err = DjangoContentTypes.AfterInsertHooks.RunHooks(ctx, exec, DjangoContentTypeSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = DjangoContentTypes.AfterUpdateHooks.RunHooks(ctx, exec, DjangoContentTypeSlice{o}) + case bob.QueryTypeDelete: + ctx, err = DjangoContentTypes.AfterDeleteHooks.RunHooks(ctx, exec, DjangoContentTypeSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the DjangoContentType +func (o *DjangoContentType) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *DjangoContentType) pkEQ() dialect.Expression { + return mysql.Quote("django_content_type", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the DjangoContentType +func (o *DjangoContentType) Update(ctx context.Context, exec bob.Executor, s *DjangoContentTypeSetter) error { + _, err := DjangoContentTypes.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single DjangoContentType record with an executor +func (o *DjangoContentType) Delete(ctx context.Context, exec bob.Executor) error { + _, err := DjangoContentTypes.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the DjangoContentType using the executor +func (o *DjangoContentType) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := DjangoContentTypes.Query( + sm.Where(DjangoContentTypes.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after DjangoContentTypeSlice is retrieved from the database +func (o DjangoContentTypeSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoContentTypes.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = DjangoContentTypes.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = DjangoContentTypes.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = DjangoContentTypes.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o DjangoContentTypeSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("django_content_type", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o DjangoContentTypeSlice) copyMatchingRows(from ...*DjangoContentType) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o DjangoContentTypeSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoContentTypes.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoContentType: + o.copyMatchingRows(retrieved) + case []*DjangoContentType: + o.copyMatchingRows(retrieved...) + case DjangoContentTypeSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoContentType or a slice of DjangoContentType + // then run the AfterUpdateHooks on the slice + _, err = DjangoContentTypes.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o DjangoContentTypeSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoContentTypes.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoContentType: + o.copyMatchingRows(retrieved) + case []*DjangoContentType: + o.copyMatchingRows(retrieved...) + case DjangoContentTypeSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoContentType or a slice of DjangoContentType + // then run the AfterDeleteHooks on the slice + _, err = DjangoContentTypes.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o DjangoContentTypeSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals DjangoContentTypeSetter) error { + _, err := DjangoContentTypes.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o DjangoContentTypeSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := DjangoContentTypes.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o DjangoContentTypeSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := DjangoContentTypes.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// ContentTypeAuthPermissions starts a query for related objects on auth_permission +func (o *DjangoContentType) ContentTypeAuthPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthPermissionsQuery { + return AuthPermissions.Query(append(mods, + sm.Where(AuthPermissions.Columns.ContentTypeID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os DjangoContentTypeSlice) ContentTypeAuthPermissions(mods ...bob.Mod[*dialect.SelectQuery]) AuthPermissionsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthPermissions.Query(append(mods, + sm.Where(mysql.Group(AuthPermissions.Columns.ContentTypeID).OP("IN", PKArgExpr)), + )...) +} + +// ContentTypeDjangoAdminLogs starts a query for related objects on django_admin_log +func (o *DjangoContentType) ContentTypeDjangoAdminLogs(mods ...bob.Mod[*dialect.SelectQuery]) DjangoAdminLogsQuery { + return DjangoAdminLogs.Query(append(mods, + sm.Where(DjangoAdminLogs.Columns.ContentTypeID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os DjangoContentTypeSlice) ContentTypeDjangoAdminLogs(mods ...bob.Mod[*dialect.SelectQuery]) DjangoAdminLogsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return DjangoAdminLogs.Query(append(mods, + sm.Where(mysql.Group(DjangoAdminLogs.Columns.ContentTypeID).OP("IN", PKArgExpr)), + )...) +} + +func insertDjangoContentTypeContentTypeAuthPermissions0(ctx context.Context, exec bob.Executor, authPermissions1 []*AuthPermissionSetter, djangoContentType0 *DjangoContentType) (AuthPermissionSlice, error) { + for i := range authPermissions1 { + authPermissions1[i].ContentTypeID = omit.From(djangoContentType0.ID) + } + + ret, err := AuthPermissions.Insert(bob.ToMods(authPermissions1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertDjangoContentTypeContentTypeAuthPermissions0: %w", err) + } + + return ret, nil +} + +func attachDjangoContentTypeContentTypeAuthPermissions0(ctx context.Context, exec bob.Executor, count int, authPermissions1 AuthPermissionSlice, djangoContentType0 *DjangoContentType) (AuthPermissionSlice, error) { + setter := &AuthPermissionSetter{ + ContentTypeID: omit.From(djangoContentType0.ID), + } + + err := authPermissions1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachDjangoContentTypeContentTypeAuthPermissions0: %w", err) + } + + return authPermissions1, nil +} + +func (djangoContentType0 *DjangoContentType) InsertContentTypeAuthPermissions(ctx context.Context, exec bob.Executor, related ...*AuthPermissionSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + authPermissions1, err := insertDjangoContentTypeContentTypeAuthPermissions0(ctx, exec, related, djangoContentType0) + if err != nil { + return err + } + + djangoContentType0.R.ContentTypeAuthPermissions = append(djangoContentType0.R.ContentTypeAuthPermissions, authPermissions1...) + + for _, rel := range authPermissions1 { + rel.R.ContentTypeDjangoContentType = djangoContentType0 + } + return nil +} + +func (djangoContentType0 *DjangoContentType) AttachContentTypeAuthPermissions(ctx context.Context, exec bob.Executor, related ...*AuthPermission) error { + if len(related) == 0 { + return nil + } + + var err error + authPermissions1 := AuthPermissionSlice(related) + + _, err = attachDjangoContentTypeContentTypeAuthPermissions0(ctx, exec, len(related), authPermissions1, djangoContentType0) + if err != nil { + return err + } + + djangoContentType0.R.ContentTypeAuthPermissions = append(djangoContentType0.R.ContentTypeAuthPermissions, authPermissions1...) + + for _, rel := range related { + rel.R.ContentTypeDjangoContentType = djangoContentType0 + } + + return nil +} + +func insertDjangoContentTypeContentTypeDjangoAdminLogs0(ctx context.Context, exec bob.Executor, djangoAdminLogs1 []*DjangoAdminLogSetter, djangoContentType0 *DjangoContentType) (DjangoAdminLogSlice, error) { + for i := range djangoAdminLogs1 { + djangoAdminLogs1[i].ContentTypeID = omitnull.From(djangoContentType0.ID) + } + + ret, err := DjangoAdminLogs.Insert(bob.ToMods(djangoAdminLogs1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertDjangoContentTypeContentTypeDjangoAdminLogs0: %w", err) + } + + return ret, nil +} + +func attachDjangoContentTypeContentTypeDjangoAdminLogs0(ctx context.Context, exec bob.Executor, count int, djangoAdminLogs1 DjangoAdminLogSlice, djangoContentType0 *DjangoContentType) (DjangoAdminLogSlice, error) { + setter := &DjangoAdminLogSetter{ + ContentTypeID: omitnull.From(djangoContentType0.ID), + } + + err := djangoAdminLogs1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachDjangoContentTypeContentTypeDjangoAdminLogs0: %w", err) + } + + return djangoAdminLogs1, nil +} + +func (djangoContentType0 *DjangoContentType) InsertContentTypeDjangoAdminLogs(ctx context.Context, exec bob.Executor, related ...*DjangoAdminLogSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + djangoAdminLogs1, err := insertDjangoContentTypeContentTypeDjangoAdminLogs0(ctx, exec, related, djangoContentType0) + if err != nil { + return err + } + + djangoContentType0.R.ContentTypeDjangoAdminLogs = append(djangoContentType0.R.ContentTypeDjangoAdminLogs, djangoAdminLogs1...) + + for _, rel := range djangoAdminLogs1 { + rel.R.ContentTypeDjangoContentType = djangoContentType0 + } + return nil +} + +func (djangoContentType0 *DjangoContentType) AttachContentTypeDjangoAdminLogs(ctx context.Context, exec bob.Executor, related ...*DjangoAdminLog) error { + if len(related) == 0 { + return nil + } + + var err error + djangoAdminLogs1 := DjangoAdminLogSlice(related) + + _, err = attachDjangoContentTypeContentTypeDjangoAdminLogs0(ctx, exec, len(related), djangoAdminLogs1, djangoContentType0) + if err != nil { + return err + } + + djangoContentType0.R.ContentTypeDjangoAdminLogs = append(djangoContentType0.R.ContentTypeDjangoAdminLogs, djangoAdminLogs1...) + + for _, rel := range related { + rel.R.ContentTypeDjangoContentType = djangoContentType0 + } + + return nil +} + +type djangoContentTypeWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + AppLabel mysql.WhereMod[Q, string] + Model mysql.WhereMod[Q, string] +} + +func (djangoContentTypeWhere[Q]) AliasedAs(alias string) djangoContentTypeWhere[Q] { + return buildDjangoContentTypeWhere[Q](buildDjangoContentTypeColumns(alias)) +} + +func buildDjangoContentTypeWhere[Q mysql.Filterable](cols djangoContentTypeColumns) djangoContentTypeWhere[Q] { + return djangoContentTypeWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + AppLabel: mysql.Where[Q, string](cols.AppLabel), + Model: mysql.Where[Q, string](cols.Model), + } +} + +func (o *DjangoContentType) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "ContentTypeAuthPermissions": + rels, ok := retrieved.(AuthPermissionSlice) + if !ok { + return fmt.Errorf("djangoContentType cannot load %T as %q", retrieved, name) + } + + o.R.ContentTypeAuthPermissions = rels + + for _, rel := range rels { + if rel != nil { + rel.R.ContentTypeDjangoContentType = o + } + } + return nil + case "ContentTypeDjangoAdminLogs": + rels, ok := retrieved.(DjangoAdminLogSlice) + if !ok { + return fmt.Errorf("djangoContentType cannot load %T as %q", retrieved, name) + } + + o.R.ContentTypeDjangoAdminLogs = rels + + for _, rel := range rels { + if rel != nil { + rel.R.ContentTypeDjangoContentType = o + } + } + return nil + default: + return fmt.Errorf("djangoContentType has no relationship %q", name) + } +} + +type djangoContentTypePreloader struct{} + +func buildDjangoContentTypePreloader() djangoContentTypePreloader { + return djangoContentTypePreloader{} +} + +type djangoContentTypeThenLoader[Q orm.Loadable] struct { + ContentTypeAuthPermissions func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ContentTypeDjangoAdminLogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildDjangoContentTypeThenLoader[Q orm.Loadable]() djangoContentTypeThenLoader[Q] { + type ContentTypeAuthPermissionsLoadInterface interface { + LoadContentTypeAuthPermissions(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ContentTypeDjangoAdminLogsLoadInterface interface { + LoadContentTypeDjangoAdminLogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return djangoContentTypeThenLoader[Q]{ + ContentTypeAuthPermissions: thenLoadBuilder[Q]( + "ContentTypeAuthPermissions", + func(ctx context.Context, exec bob.Executor, retrieved ContentTypeAuthPermissionsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadContentTypeAuthPermissions(ctx, exec, mods...) + }, + ), + ContentTypeDjangoAdminLogs: thenLoadBuilder[Q]( + "ContentTypeDjangoAdminLogs", + func(ctx context.Context, exec bob.Executor, retrieved ContentTypeDjangoAdminLogsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadContentTypeDjangoAdminLogs(ctx, exec, mods...) + }, + ), + } +} + +// LoadContentTypeAuthPermissions loads the djangoContentType's ContentTypeAuthPermissions into the .R struct +func (o *DjangoContentType) LoadContentTypeAuthPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ContentTypeAuthPermissions = nil + + related, err := o.ContentTypeAuthPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.ContentTypeDjangoContentType = o + } + + o.R.ContentTypeAuthPermissions = related + return nil +} + +// LoadContentTypeAuthPermissions loads the djangoContentType's ContentTypeAuthPermissions into the .R struct +func (os DjangoContentTypeSlice) LoadContentTypeAuthPermissions(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authPermissions, err := os.ContentTypeAuthPermissions(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.ContentTypeAuthPermissions = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authPermissions { + + if !(o.ID == rel.ContentTypeID) { + continue + } + + rel.R.ContentTypeDjangoContentType = o + + o.R.ContentTypeAuthPermissions = append(o.R.ContentTypeAuthPermissions, rel) + } + } + + return nil +} + +// LoadContentTypeDjangoAdminLogs loads the djangoContentType's ContentTypeDjangoAdminLogs into the .R struct +func (o *DjangoContentType) LoadContentTypeDjangoAdminLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ContentTypeDjangoAdminLogs = nil + + related, err := o.ContentTypeDjangoAdminLogs(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.ContentTypeDjangoContentType = o + } + + o.R.ContentTypeDjangoAdminLogs = related + return nil +} + +// LoadContentTypeDjangoAdminLogs loads the djangoContentType's ContentTypeDjangoAdminLogs into the .R struct +func (os DjangoContentTypeSlice) LoadContentTypeDjangoAdminLogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + djangoAdminLogs, err := os.ContentTypeDjangoAdminLogs(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.ContentTypeDjangoAdminLogs = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range djangoAdminLogs { + + if !rel.ContentTypeID.IsValue() { + continue + } + if !(rel.ContentTypeID.IsValue() && o.ID == rel.ContentTypeID.MustGet()) { + continue + } + + rel.R.ContentTypeDjangoContentType = o + + o.R.ContentTypeDjangoAdminLogs = append(o.R.ContentTypeDjangoAdminLogs, rel) + } + } + + return nil +} + +type djangoContentTypeJoins[Q dialect.Joinable] struct { + typ string + ContentTypeAuthPermissions modAs[Q, authPermissionColumns] + ContentTypeDjangoAdminLogs modAs[Q, djangoAdminLogColumns] +} + +func (j djangoContentTypeJoins[Q]) aliasedAs(alias string) djangoContentTypeJoins[Q] { + return buildDjangoContentTypeJoins[Q](buildDjangoContentTypeColumns(alias), j.typ) +} + +func buildDjangoContentTypeJoins[Q dialect.Joinable](cols djangoContentTypeColumns, typ string) djangoContentTypeJoins[Q] { + return djangoContentTypeJoins[Q]{ + typ: typ, + ContentTypeAuthPermissions: modAs[Q, authPermissionColumns]{ + c: AuthPermissions.Columns, + f: func(to authPermissionColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthPermissions.Name().As(to.Alias())).On( + to.ContentTypeID.EQ(cols.ID), + )) + } + + return mods + }, + }, + ContentTypeDjangoAdminLogs: modAs[Q, djangoAdminLogColumns]{ + c: DjangoAdminLogs.Columns, + f: func(to djangoAdminLogColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, DjangoAdminLogs.Name().As(to.Alias())).On( + to.ContentTypeID.EQ(cols.ID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/django_migrations.bob.go b/database/storage_service/models/django_migrations.bob.go new file mode 100644 index 0000000..df0e33f --- /dev/null +++ b/database/storage_service/models/django_migrations.bob.go @@ -0,0 +1,419 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "io" + "time" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" +) + +// DjangoMigration is an object representing the database table. +type DjangoMigration struct { + ID int32 `db:"id,pk,autoincr" ` + App string `db:"app" ` + Name string `db:"name" ` + Applied time.Time `db:"applied" ` +} + +// DjangoMigrationSlice is an alias for a slice of pointers to DjangoMigration. +// This should almost always be used instead of []*DjangoMigration. +type DjangoMigrationSlice []*DjangoMigration + +// DjangoMigrations contains methods to work with the django_migrations table +var DjangoMigrations = mysql.NewTablex[*DjangoMigration, DjangoMigrationSlice, *DjangoMigrationSetter]("django_migrations", buildDjangoMigrationColumns("django_migrations"), []string{"id"}) + +// DjangoMigrationsQuery is a query on the django_migrations table +type DjangoMigrationsQuery = *mysql.ViewQuery[*DjangoMigration, DjangoMigrationSlice] + +func buildDjangoMigrationColumns(alias string) djangoMigrationColumns { + return djangoMigrationColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "app", "name", "applied", + ).WithParent("django_migrations"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + App: mysql.Quote(alias, "app"), + Name: mysql.Quote(alias, "name"), + Applied: mysql.Quote(alias, "applied"), + } +} + +type djangoMigrationColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + App mysql.Expression + Name mysql.Expression + Applied mysql.Expression +} + +func (c djangoMigrationColumns) Alias() string { + return c.tableAlias +} + +func (djangoMigrationColumns) AliasedAs(alias string) djangoMigrationColumns { + return buildDjangoMigrationColumns(alias) +} + +// DjangoMigrationSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type DjangoMigrationSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + App omit.Val[string] `db:"app" ` + Name omit.Val[string] `db:"name" ` + Applied omit.Val[time.Time] `db:"applied" ` +} + +func (s DjangoMigrationSetter) SetColumns() []string { + vals := make([]string, 0, 4) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.App.IsValue() { + vals = append(vals, "app") + } + if s.Name.IsValue() { + vals = append(vals, "name") + } + if s.Applied.IsValue() { + vals = append(vals, "applied") + } + return vals +} + +func (s DjangoMigrationSetter) Overwrite(t *DjangoMigration) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.App.IsValue() { + t.App = s.App.MustGet() + } + if s.Name.IsValue() { + t.Name = s.Name.MustGet() + } + if s.Applied.IsValue() { + t.Applied = s.Applied.MustGet() + } +} + +func (s *DjangoMigrationSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoMigrations.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.App.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.App.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Name.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Name.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Applied.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Applied.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s DjangoMigrationSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("django_migrations")...) +} + +func (s DjangoMigrationSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 4) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.App.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "app")...), + mysql.Arg(s.App), + }}) + } + + if s.Name.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "name")...), + mysql.Arg(s.Name), + }}) + } + + if s.Applied.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "applied")...), + mysql.Arg(s.Applied), + }}) + } + + return exprs +} + +// FindDjangoMigration retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindDjangoMigration(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*DjangoMigration, error) { + if len(cols) == 0 { + return DjangoMigrations.Query( + sm.Where(DjangoMigrations.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return DjangoMigrations.Query( + sm.Where(DjangoMigrations.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(DjangoMigrations.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// DjangoMigrationExists checks the presence of a single record by primary key +func DjangoMigrationExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return DjangoMigrations.Query( + sm.Where(DjangoMigrations.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after DjangoMigration is retrieved from the database +func (o *DjangoMigration) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoMigrations.AfterSelectHooks.RunHooks(ctx, exec, DjangoMigrationSlice{o}) + case bob.QueryTypeInsert: + ctx, err = DjangoMigrations.AfterInsertHooks.RunHooks(ctx, exec, DjangoMigrationSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = DjangoMigrations.AfterUpdateHooks.RunHooks(ctx, exec, DjangoMigrationSlice{o}) + case bob.QueryTypeDelete: + ctx, err = DjangoMigrations.AfterDeleteHooks.RunHooks(ctx, exec, DjangoMigrationSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the DjangoMigration +func (o *DjangoMigration) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *DjangoMigration) pkEQ() dialect.Expression { + return mysql.Quote("django_migrations", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the DjangoMigration +func (o *DjangoMigration) Update(ctx context.Context, exec bob.Executor, s *DjangoMigrationSetter) error { + _, err := DjangoMigrations.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single DjangoMigration record with an executor +func (o *DjangoMigration) Delete(ctx context.Context, exec bob.Executor) error { + _, err := DjangoMigrations.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the DjangoMigration using the executor +func (o *DjangoMigration) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := DjangoMigrations.Query( + sm.Where(DjangoMigrations.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + + *o = *o2 + + return nil +} + +// AfterQueryHook is called after DjangoMigrationSlice is retrieved from the database +func (o DjangoMigrationSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoMigrations.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = DjangoMigrations.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = DjangoMigrations.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = DjangoMigrations.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o DjangoMigrationSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("django_migrations", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o DjangoMigrationSlice) copyMatchingRows(from ...*DjangoMigration) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o DjangoMigrationSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoMigrations.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoMigration: + o.copyMatchingRows(retrieved) + case []*DjangoMigration: + o.copyMatchingRows(retrieved...) + case DjangoMigrationSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoMigration or a slice of DjangoMigration + // then run the AfterUpdateHooks on the slice + _, err = DjangoMigrations.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o DjangoMigrationSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoMigrations.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoMigration: + o.copyMatchingRows(retrieved) + case []*DjangoMigration: + o.copyMatchingRows(retrieved...) + case DjangoMigrationSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoMigration or a slice of DjangoMigration + // then run the AfterDeleteHooks on the slice + _, err = DjangoMigrations.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o DjangoMigrationSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals DjangoMigrationSetter) error { + _, err := DjangoMigrations.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o DjangoMigrationSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := DjangoMigrations.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o DjangoMigrationSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := DjangoMigrations.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +type djangoMigrationWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + App mysql.WhereMod[Q, string] + Name mysql.WhereMod[Q, string] + Applied mysql.WhereMod[Q, time.Time] +} + +func (djangoMigrationWhere[Q]) AliasedAs(alias string) djangoMigrationWhere[Q] { + return buildDjangoMigrationWhere[Q](buildDjangoMigrationColumns(alias)) +} + +func buildDjangoMigrationWhere[Q mysql.Filterable](cols djangoMigrationColumns) djangoMigrationWhere[Q] { + return djangoMigrationWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + App: mysql.Where[Q, string](cols.App), + Name: mysql.Where[Q, string](cols.Name), + Applied: mysql.Where[Q, time.Time](cols.Applied), + } +} diff --git a/database/storage_service/models/django_session.bob.go b/database/storage_service/models/django_session.bob.go new file mode 100644 index 0000000..12c4cd0 --- /dev/null +++ b/database/storage_service/models/django_session.bob.go @@ -0,0 +1,395 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "io" + "time" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" +) + +// DjangoSession is an object representing the database table. +type DjangoSession struct { + SessionKey string `db:"session_key,pk" ` + SessionData string `db:"session_data" ` + ExpireDate time.Time `db:"expire_date" ` +} + +// DjangoSessionSlice is an alias for a slice of pointers to DjangoSession. +// This should almost always be used instead of []*DjangoSession. +type DjangoSessionSlice []*DjangoSession + +// DjangoSessions contains methods to work with the django_session table +var DjangoSessions = mysql.NewTablex[*DjangoSession, DjangoSessionSlice, *DjangoSessionSetter]("django_session", buildDjangoSessionColumns("django_session"), []string{"session_key"}) + +// DjangoSessionsQuery is a query on the django_session table +type DjangoSessionsQuery = *mysql.ViewQuery[*DjangoSession, DjangoSessionSlice] + +func buildDjangoSessionColumns(alias string) djangoSessionColumns { + return djangoSessionColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "session_key", "session_data", "expire_date", + ).WithParent("django_session"), + tableAlias: alias, + SessionKey: mysql.Quote(alias, "session_key"), + SessionData: mysql.Quote(alias, "session_data"), + ExpireDate: mysql.Quote(alias, "expire_date"), + } +} + +type djangoSessionColumns struct { + expr.ColumnsExpr + tableAlias string + SessionKey mysql.Expression + SessionData mysql.Expression + ExpireDate mysql.Expression +} + +func (c djangoSessionColumns) Alias() string { + return c.tableAlias +} + +func (djangoSessionColumns) AliasedAs(alias string) djangoSessionColumns { + return buildDjangoSessionColumns(alias) +} + +// DjangoSessionSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type DjangoSessionSetter struct { + SessionKey omit.Val[string] `db:"session_key,pk" ` + SessionData omit.Val[string] `db:"session_data" ` + ExpireDate omit.Val[time.Time] `db:"expire_date" ` +} + +func (s DjangoSessionSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.SessionKey.IsValue() { + vals = append(vals, "session_key") + } + if s.SessionData.IsValue() { + vals = append(vals, "session_data") + } + if s.ExpireDate.IsValue() { + vals = append(vals, "expire_date") + } + return vals +} + +func (s DjangoSessionSetter) Overwrite(t *DjangoSession) { + if s.SessionKey.IsValue() { + t.SessionKey = s.SessionKey.MustGet() + } + if s.SessionData.IsValue() { + t.SessionData = s.SessionData.MustGet() + } + if s.ExpireDate.IsValue() { + t.ExpireDate = s.ExpireDate.MustGet() + } +} + +func (s *DjangoSessionSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoSessions.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SessionKey.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SessionKey.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SessionData.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SessionData.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ExpireDate.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ExpireDate.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s DjangoSessionSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("django_session")...) +} + +func (s DjangoSessionSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.SessionKey.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "session_key")...), + mysql.Arg(s.SessionKey), + }}) + } + + if s.SessionData.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "session_data")...), + mysql.Arg(s.SessionData), + }}) + } + + if s.ExpireDate.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "expire_date")...), + mysql.Arg(s.ExpireDate), + }}) + } + + return exprs +} + +// FindDjangoSession retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindDjangoSession(ctx context.Context, exec bob.Executor, SessionKeyPK string, cols ...string) (*DjangoSession, error) { + if len(cols) == 0 { + return DjangoSessions.Query( + sm.Where(DjangoSessions.Columns.SessionKey.EQ(mysql.Arg(SessionKeyPK))), + ).One(ctx, exec) + } + + return DjangoSessions.Query( + sm.Where(DjangoSessions.Columns.SessionKey.EQ(mysql.Arg(SessionKeyPK))), + sm.Columns(DjangoSessions.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// DjangoSessionExists checks the presence of a single record by primary key +func DjangoSessionExists(ctx context.Context, exec bob.Executor, SessionKeyPK string) (bool, error) { + return DjangoSessions.Query( + sm.Where(DjangoSessions.Columns.SessionKey.EQ(mysql.Arg(SessionKeyPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after DjangoSession is retrieved from the database +func (o *DjangoSession) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoSessions.AfterSelectHooks.RunHooks(ctx, exec, DjangoSessionSlice{o}) + case bob.QueryTypeInsert: + ctx, err = DjangoSessions.AfterInsertHooks.RunHooks(ctx, exec, DjangoSessionSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = DjangoSessions.AfterUpdateHooks.RunHooks(ctx, exec, DjangoSessionSlice{o}) + case bob.QueryTypeDelete: + ctx, err = DjangoSessions.AfterDeleteHooks.RunHooks(ctx, exec, DjangoSessionSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the DjangoSession +func (o *DjangoSession) primaryKeyVals() bob.Expression { + return mysql.Arg(o.SessionKey) +} + +func (o *DjangoSession) pkEQ() dialect.Expression { + return mysql.Quote("django_session", "session_key").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the DjangoSession +func (o *DjangoSession) Update(ctx context.Context, exec bob.Executor, s *DjangoSessionSetter) error { + _, err := DjangoSessions.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single DjangoSession record with an executor +func (o *DjangoSession) Delete(ctx context.Context, exec bob.Executor) error { + _, err := DjangoSessions.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the DjangoSession using the executor +func (o *DjangoSession) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := DjangoSessions.Query( + sm.Where(DjangoSessions.Columns.SessionKey.EQ(mysql.Arg(o.SessionKey))), + ).One(ctx, exec) + if err != nil { + return err + } + + *o = *o2 + + return nil +} + +// AfterQueryHook is called after DjangoSessionSlice is retrieved from the database +func (o DjangoSessionSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoSessions.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = DjangoSessions.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = DjangoSessions.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = DjangoSessions.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o DjangoSessionSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("django_session", "session_key").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o DjangoSessionSlice) copyMatchingRows(from ...*DjangoSession) { + for i, old := range o { + for _, new := range from { + if new.SessionKey != old.SessionKey { + continue + } + + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o DjangoSessionSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoSessions.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoSession: + o.copyMatchingRows(retrieved) + case []*DjangoSession: + o.copyMatchingRows(retrieved...) + case DjangoSessionSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoSession or a slice of DjangoSession + // then run the AfterUpdateHooks on the slice + _, err = DjangoSessions.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o DjangoSessionSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoSessions.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoSession: + o.copyMatchingRows(retrieved) + case []*DjangoSession: + o.copyMatchingRows(retrieved...) + case DjangoSessionSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoSession or a slice of DjangoSession + // then run the AfterDeleteHooks on the slice + _, err = DjangoSessions.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o DjangoSessionSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals DjangoSessionSetter) error { + _, err := DjangoSessions.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o DjangoSessionSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := DjangoSessions.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o DjangoSessionSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := DjangoSessions.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +type djangoSessionWhere[Q mysql.Filterable] struct { + SessionKey mysql.WhereMod[Q, string] + SessionData mysql.WhereMod[Q, string] + ExpireDate mysql.WhereMod[Q, time.Time] +} + +func (djangoSessionWhere[Q]) AliasedAs(alias string) djangoSessionWhere[Q] { + return buildDjangoSessionWhere[Q](buildDjangoSessionColumns(alias)) +} + +func buildDjangoSessionWhere[Q mysql.Filterable](cols djangoSessionColumns) djangoSessionWhere[Q] { + return djangoSessionWhere[Q]{ + SessionKey: mysql.Where[Q, string](cols.SessionKey), + SessionData: mysql.Where[Q, string](cols.SessionData), + ExpireDate: mysql.Where[Q, time.Time](cols.ExpireDate), + } +} diff --git a/database/storage_service/models/django_site.bob.go b/database/storage_service/models/django_site.bob.go new file mode 100644 index 0000000..59cb0d2 --- /dev/null +++ b/database/storage_service/models/django_site.bob.go @@ -0,0 +1,394 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" +) + +// DjangoSite is an object representing the database table. +type DjangoSite struct { + ID int32 `db:"id,pk,autoincr" ` + Domain string `db:"domain" ` + Name string `db:"name" ` +} + +// DjangoSiteSlice is an alias for a slice of pointers to DjangoSite. +// This should almost always be used instead of []*DjangoSite. +type DjangoSiteSlice []*DjangoSite + +// DjangoSites contains methods to work with the django_site table +var DjangoSites = mysql.NewTablex[*DjangoSite, DjangoSiteSlice, *DjangoSiteSetter]("django_site", buildDjangoSiteColumns("django_site"), []string{"id"}, []string{"domain"}) + +// DjangoSitesQuery is a query on the django_site table +type DjangoSitesQuery = *mysql.ViewQuery[*DjangoSite, DjangoSiteSlice] + +func buildDjangoSiteColumns(alias string) djangoSiteColumns { + return djangoSiteColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "domain", "name", + ).WithParent("django_site"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Domain: mysql.Quote(alias, "domain"), + Name: mysql.Quote(alias, "name"), + } +} + +type djangoSiteColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Domain mysql.Expression + Name mysql.Expression +} + +func (c djangoSiteColumns) Alias() string { + return c.tableAlias +} + +func (djangoSiteColumns) AliasedAs(alias string) djangoSiteColumns { + return buildDjangoSiteColumns(alias) +} + +// DjangoSiteSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type DjangoSiteSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Domain omit.Val[string] `db:"domain" ` + Name omit.Val[string] `db:"name" ` +} + +func (s DjangoSiteSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Domain.IsValue() { + vals = append(vals, "domain") + } + if s.Name.IsValue() { + vals = append(vals, "name") + } + return vals +} + +func (s DjangoSiteSetter) Overwrite(t *DjangoSite) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Domain.IsValue() { + t.Domain = s.Domain.MustGet() + } + if s.Name.IsValue() { + t.Name = s.Name.MustGet() + } +} + +func (s *DjangoSiteSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoSites.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Domain.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Domain.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Name.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Name.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s DjangoSiteSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("django_site")...) +} + +func (s DjangoSiteSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Domain.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "domain")...), + mysql.Arg(s.Domain), + }}) + } + + if s.Name.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "name")...), + mysql.Arg(s.Name), + }}) + } + + return exprs +} + +// FindDjangoSite retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindDjangoSite(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*DjangoSite, error) { + if len(cols) == 0 { + return DjangoSites.Query( + sm.Where(DjangoSites.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return DjangoSites.Query( + sm.Where(DjangoSites.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(DjangoSites.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// DjangoSiteExists checks the presence of a single record by primary key +func DjangoSiteExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return DjangoSites.Query( + sm.Where(DjangoSites.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after DjangoSite is retrieved from the database +func (o *DjangoSite) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoSites.AfterSelectHooks.RunHooks(ctx, exec, DjangoSiteSlice{o}) + case bob.QueryTypeInsert: + ctx, err = DjangoSites.AfterInsertHooks.RunHooks(ctx, exec, DjangoSiteSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = DjangoSites.AfterUpdateHooks.RunHooks(ctx, exec, DjangoSiteSlice{o}) + case bob.QueryTypeDelete: + ctx, err = DjangoSites.AfterDeleteHooks.RunHooks(ctx, exec, DjangoSiteSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the DjangoSite +func (o *DjangoSite) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *DjangoSite) pkEQ() dialect.Expression { + return mysql.Quote("django_site", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the DjangoSite +func (o *DjangoSite) Update(ctx context.Context, exec bob.Executor, s *DjangoSiteSetter) error { + _, err := DjangoSites.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single DjangoSite record with an executor +func (o *DjangoSite) Delete(ctx context.Context, exec bob.Executor) error { + _, err := DjangoSites.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the DjangoSite using the executor +func (o *DjangoSite) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := DjangoSites.Query( + sm.Where(DjangoSites.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + + *o = *o2 + + return nil +} + +// AfterQueryHook is called after DjangoSiteSlice is retrieved from the database +func (o DjangoSiteSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = DjangoSites.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = DjangoSites.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = DjangoSites.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = DjangoSites.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o DjangoSiteSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("django_site", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o DjangoSiteSlice) copyMatchingRows(from ...*DjangoSite) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o DjangoSiteSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoSites.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoSite: + o.copyMatchingRows(retrieved) + case []*DjangoSite: + o.copyMatchingRows(retrieved...) + case DjangoSiteSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoSite or a slice of DjangoSite + // then run the AfterUpdateHooks on the slice + _, err = DjangoSites.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o DjangoSiteSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return DjangoSites.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *DjangoSite: + o.copyMatchingRows(retrieved) + case []*DjangoSite: + o.copyMatchingRows(retrieved...) + case DjangoSiteSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a DjangoSite or a slice of DjangoSite + // then run the AfterDeleteHooks on the slice + _, err = DjangoSites.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o DjangoSiteSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals DjangoSiteSetter) error { + _, err := DjangoSites.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o DjangoSiteSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := DjangoSites.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o DjangoSiteSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := DjangoSites.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +type djangoSiteWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Domain mysql.WhereMod[Q, string] + Name mysql.WhereMod[Q, string] +} + +func (djangoSiteWhere[Q]) AliasedAs(alias string) djangoSiteWhere[Q] { + return buildDjangoSiteWhere[Q](buildDjangoSiteColumns(alias)) +} + +func buildDjangoSiteWhere[Q mysql.Filterable](cols djangoSiteColumns) djangoSiteWhere[Q] { + return djangoSiteWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Domain: mysql.Where[Q, string](cols.Domain), + Name: mysql.Where[Q, string](cols.Name), + } +} diff --git a/database/storage_service/models/locations_archipelago.bob.go b/database/storage_service/models/locations_archipelago.bob.go new file mode 100644 index 0000000..fdc5f0a --- /dev/null +++ b/database/storage_service/models/locations_archipelago.bob.go @@ -0,0 +1,664 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsArchipelago is an object representing the database table. +type LocationsArchipelago struct { + ID int32 `db:"id,pk,autoincr" ` + ArchipelagoURL string `db:"archipelago_url" ` + ArchipelagoUser string `db:"archipelago_user" ` + ArchipelagoPassword string `db:"archipelago_password" ` + SpaceID string `db:"space_id" ` + + R locationsArchipelagoR `db:"-" ` +} + +// LocationsArchipelagoSlice is an alias for a slice of pointers to LocationsArchipelago. +// This should almost always be used instead of []*LocationsArchipelago. +type LocationsArchipelagoSlice []*LocationsArchipelago + +// LocationsArchipelagos contains methods to work with the locations_archipelago table +var LocationsArchipelagos = mysql.NewTablex[*LocationsArchipelago, LocationsArchipelagoSlice, *LocationsArchipelagoSetter]("locations_archipelago", buildLocationsArchipelagoColumns("locations_archipelago"), []string{"id"}, []string{"space_id"}) + +// LocationsArchipelagosQuery is a query on the locations_archipelago table +type LocationsArchipelagosQuery = *mysql.ViewQuery[*LocationsArchipelago, LocationsArchipelagoSlice] + +// locationsArchipelagoR is where relationships are stored. +type locationsArchipelagoR struct { + SpaceLocationsSpace *LocationsSpace // locations_archipelago_space_id_be47fd5c_fk_locations_space_uuid +} + +func buildLocationsArchipelagoColumns(alias string) locationsArchipelagoColumns { + return locationsArchipelagoColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "archipelago_url", "archipelago_user", "archipelago_password", "space_id", + ).WithParent("locations_archipelago"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + ArchipelagoURL: mysql.Quote(alias, "archipelago_url"), + ArchipelagoUser: mysql.Quote(alias, "archipelago_user"), + ArchipelagoPassword: mysql.Quote(alias, "archipelago_password"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsArchipelagoColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + ArchipelagoURL mysql.Expression + ArchipelagoUser mysql.Expression + ArchipelagoPassword mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsArchipelagoColumns) Alias() string { + return c.tableAlias +} + +func (locationsArchipelagoColumns) AliasedAs(alias string) locationsArchipelagoColumns { + return buildLocationsArchipelagoColumns(alias) +} + +// LocationsArchipelagoSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsArchipelagoSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + ArchipelagoURL omit.Val[string] `db:"archipelago_url" ` + ArchipelagoUser omit.Val[string] `db:"archipelago_user" ` + ArchipelagoPassword omit.Val[string] `db:"archipelago_password" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsArchipelagoSetter) SetColumns() []string { + vals := make([]string, 0, 5) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.ArchipelagoURL.IsValue() { + vals = append(vals, "archipelago_url") + } + if s.ArchipelagoUser.IsValue() { + vals = append(vals, "archipelago_user") + } + if s.ArchipelagoPassword.IsValue() { + vals = append(vals, "archipelago_password") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsArchipelagoSetter) Overwrite(t *LocationsArchipelago) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.ArchipelagoURL.IsValue() { + t.ArchipelagoURL = s.ArchipelagoURL.MustGet() + } + if s.ArchipelagoUser.IsValue() { + t.ArchipelagoUser = s.ArchipelagoUser.MustGet() + } + if s.ArchipelagoPassword.IsValue() { + t.ArchipelagoPassword = s.ArchipelagoPassword.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsArchipelagoSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsArchipelagos.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ArchipelagoURL.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ArchipelagoURL.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ArchipelagoUser.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ArchipelagoUser.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ArchipelagoPassword.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ArchipelagoPassword.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsArchipelagoSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_archipelago")...) +} + +func (s LocationsArchipelagoSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 5) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.ArchipelagoURL.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "archipelago_url")...), + mysql.Arg(s.ArchipelagoURL), + }}) + } + + if s.ArchipelagoUser.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "archipelago_user")...), + mysql.Arg(s.ArchipelagoUser), + }}) + } + + if s.ArchipelagoPassword.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "archipelago_password")...), + mysql.Arg(s.ArchipelagoPassword), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsArchipelago retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsArchipelago(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsArchipelago, error) { + if len(cols) == 0 { + return LocationsArchipelagos.Query( + sm.Where(LocationsArchipelagos.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsArchipelagos.Query( + sm.Where(LocationsArchipelagos.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsArchipelagos.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsArchipelagoExists checks the presence of a single record by primary key +func LocationsArchipelagoExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsArchipelagos.Query( + sm.Where(LocationsArchipelagos.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsArchipelago is retrieved from the database +func (o *LocationsArchipelago) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsArchipelagos.AfterSelectHooks.RunHooks(ctx, exec, LocationsArchipelagoSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsArchipelagos.AfterInsertHooks.RunHooks(ctx, exec, LocationsArchipelagoSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsArchipelagos.AfterUpdateHooks.RunHooks(ctx, exec, LocationsArchipelagoSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsArchipelagos.AfterDeleteHooks.RunHooks(ctx, exec, LocationsArchipelagoSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsArchipelago +func (o *LocationsArchipelago) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsArchipelago) pkEQ() dialect.Expression { + return mysql.Quote("locations_archipelago", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsArchipelago +func (o *LocationsArchipelago) Update(ctx context.Context, exec bob.Executor, s *LocationsArchipelagoSetter) error { + _, err := LocationsArchipelagos.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsArchipelago record with an executor +func (o *LocationsArchipelago) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsArchipelagos.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsArchipelago using the executor +func (o *LocationsArchipelago) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsArchipelagos.Query( + sm.Where(LocationsArchipelagos.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsArchipelagoSlice is retrieved from the database +func (o LocationsArchipelagoSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsArchipelagos.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsArchipelagos.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsArchipelagos.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsArchipelagos.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsArchipelagoSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_archipelago", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsArchipelagoSlice) copyMatchingRows(from ...*LocationsArchipelago) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsArchipelagoSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsArchipelagos.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsArchipelago: + o.copyMatchingRows(retrieved) + case []*LocationsArchipelago: + o.copyMatchingRows(retrieved...) + case LocationsArchipelagoSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsArchipelago or a slice of LocationsArchipelago + // then run the AfterUpdateHooks on the slice + _, err = LocationsArchipelagos.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsArchipelagoSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsArchipelagos.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsArchipelago: + o.copyMatchingRows(retrieved) + case []*LocationsArchipelago: + o.copyMatchingRows(retrieved...) + case LocationsArchipelagoSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsArchipelago or a slice of LocationsArchipelago + // then run the AfterDeleteHooks on the slice + _, err = LocationsArchipelagos.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsArchipelagoSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsArchipelagoSetter) error { + _, err := LocationsArchipelagos.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsArchipelagoSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsArchipelagos.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsArchipelagoSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsArchipelagos.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsArchipelago) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsArchipelagoSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsArchipelagoSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsArchipelago0 *LocationsArchipelago, locationsSpace1 *LocationsSpace) (*LocationsArchipelago, error) { + setter := &LocationsArchipelagoSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsArchipelago0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsArchipelagoSpaceLocationsSpace0: %w", err) + } + + return locationsArchipelago0, nil +} + +func (locationsArchipelago0 *LocationsArchipelago) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsArchipelagoSpaceLocationsSpace0(ctx, exec, 1, locationsArchipelago0, locationsSpace1) + if err != nil { + return err + } + + locationsArchipelago0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsArchipelago = locationsArchipelago0 + + return nil +} + +func (locationsArchipelago0 *LocationsArchipelago) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsArchipelagoSpaceLocationsSpace0(ctx, exec, 1, locationsArchipelago0, locationsSpace1) + if err != nil { + return err + } + + locationsArchipelago0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsArchipelago = locationsArchipelago0 + + return nil +} + +type locationsArchipelagoWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + ArchipelagoURL mysql.WhereMod[Q, string] + ArchipelagoUser mysql.WhereMod[Q, string] + ArchipelagoPassword mysql.WhereMod[Q, string] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsArchipelagoWhere[Q]) AliasedAs(alias string) locationsArchipelagoWhere[Q] { + return buildLocationsArchipelagoWhere[Q](buildLocationsArchipelagoColumns(alias)) +} + +func buildLocationsArchipelagoWhere[Q mysql.Filterable](cols locationsArchipelagoColumns) locationsArchipelagoWhere[Q] { + return locationsArchipelagoWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + ArchipelagoURL: mysql.Where[Q, string](cols.ArchipelagoURL), + ArchipelagoUser: mysql.Where[Q, string](cols.ArchipelagoUser), + ArchipelagoPassword: mysql.Where[Q, string](cols.ArchipelagoPassword), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsArchipelago) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsArchipelago cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsArchipelago = o + } + return nil + default: + return fmt.Errorf("locationsArchipelago has no relationship %q", name) + } +} + +type locationsArchipelagoPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsArchipelagoPreloader() locationsArchipelagoPreloader { + return locationsArchipelagoPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsArchipelagos, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsArchipelagoThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsArchipelagoThenLoader[Q orm.Loadable]() locationsArchipelagoThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsArchipelagoThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsArchipelago's SpaceLocationsSpace into the .R struct +func (o *LocationsArchipelago) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsArchipelago = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsArchipelago's SpaceLocationsSpace into the .R struct +func (os LocationsArchipelagoSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsArchipelago = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsArchipelagoJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsArchipelagoJoins[Q]) aliasedAs(alias string) locationsArchipelagoJoins[Q] { + return buildLocationsArchipelagoJoins[Q](buildLocationsArchipelagoColumns(alias), j.typ) +} + +func buildLocationsArchipelagoJoins[Q dialect.Joinable](cols locationsArchipelagoColumns, typ string) locationsArchipelagoJoins[Q] { + return locationsArchipelagoJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_arkivum.bob.go b/database/storage_service/models/locations_arkivum.bob.go new file mode 100644 index 0000000..452b0cd --- /dev/null +++ b/database/storage_service/models/locations_arkivum.bob.go @@ -0,0 +1,666 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsArkivum is an object representing the database table. +type LocationsArkivum struct { + ID int32 `db:"id,pk,autoincr" ` + Host string `db:"host" ` + RemoteUser null.Val[string] `db:"remote_user" ` + RemoteName null.Val[string] `db:"remote_name" ` + SpaceID string `db:"space_id" ` + + R locationsArkivumR `db:"-" ` +} + +// LocationsArkivumSlice is an alias for a slice of pointers to LocationsArkivum. +// This should almost always be used instead of []*LocationsArkivum. +type LocationsArkivumSlice []*LocationsArkivum + +// LocationsArkivums contains methods to work with the locations_arkivum table +var LocationsArkivums = mysql.NewTablex[*LocationsArkivum, LocationsArkivumSlice, *LocationsArkivumSetter]("locations_arkivum", buildLocationsArkivumColumns("locations_arkivum"), []string{"id"}, []string{"space_id"}) + +// LocationsArkivumsQuery is a query on the locations_arkivum table +type LocationsArkivumsQuery = *mysql.ViewQuery[*LocationsArkivum, LocationsArkivumSlice] + +// locationsArkivumR is where relationships are stored. +type locationsArkivumR struct { + SpaceLocationsSpace *LocationsSpace // locations_arkivum_space_id_d159e309_fk_locations_space_uuid +} + +func buildLocationsArkivumColumns(alias string) locationsArkivumColumns { + return locationsArkivumColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "host", "remote_user", "remote_name", "space_id", + ).WithParent("locations_arkivum"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Host: mysql.Quote(alias, "host"), + RemoteUser: mysql.Quote(alias, "remote_user"), + RemoteName: mysql.Quote(alias, "remote_name"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsArkivumColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Host mysql.Expression + RemoteUser mysql.Expression + RemoteName mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsArkivumColumns) Alias() string { + return c.tableAlias +} + +func (locationsArkivumColumns) AliasedAs(alias string) locationsArkivumColumns { + return buildLocationsArkivumColumns(alias) +} + +// LocationsArkivumSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsArkivumSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Host omit.Val[string] `db:"host" ` + RemoteUser omitnull.Val[string] `db:"remote_user" ` + RemoteName omitnull.Val[string] `db:"remote_name" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsArkivumSetter) SetColumns() []string { + vals := make([]string, 0, 5) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Host.IsValue() { + vals = append(vals, "host") + } + if !s.RemoteUser.IsUnset() { + vals = append(vals, "remote_user") + } + if !s.RemoteName.IsUnset() { + vals = append(vals, "remote_name") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsArkivumSetter) Overwrite(t *LocationsArkivum) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Host.IsValue() { + t.Host = s.Host.MustGet() + } + if !s.RemoteUser.IsUnset() { + t.RemoteUser = s.RemoteUser.MustGetNull() + } + if !s.RemoteName.IsUnset() { + t.RemoteName = s.RemoteName.MustGetNull() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsArkivumSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsArkivums.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Host.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Host.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.RemoteUser.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RemoteUser.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.RemoteName.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RemoteName.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsArkivumSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_arkivum")...) +} + +func (s LocationsArkivumSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 5) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Host.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "host")...), + mysql.Arg(s.Host), + }}) + } + + if !s.RemoteUser.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "remote_user")...), + mysql.Arg(s.RemoteUser), + }}) + } + + if !s.RemoteName.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "remote_name")...), + mysql.Arg(s.RemoteName), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsArkivum retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsArkivum(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsArkivum, error) { + if len(cols) == 0 { + return LocationsArkivums.Query( + sm.Where(LocationsArkivums.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsArkivums.Query( + sm.Where(LocationsArkivums.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsArkivums.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsArkivumExists checks the presence of a single record by primary key +func LocationsArkivumExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsArkivums.Query( + sm.Where(LocationsArkivums.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsArkivum is retrieved from the database +func (o *LocationsArkivum) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsArkivums.AfterSelectHooks.RunHooks(ctx, exec, LocationsArkivumSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsArkivums.AfterInsertHooks.RunHooks(ctx, exec, LocationsArkivumSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsArkivums.AfterUpdateHooks.RunHooks(ctx, exec, LocationsArkivumSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsArkivums.AfterDeleteHooks.RunHooks(ctx, exec, LocationsArkivumSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsArkivum +func (o *LocationsArkivum) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsArkivum) pkEQ() dialect.Expression { + return mysql.Quote("locations_arkivum", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsArkivum +func (o *LocationsArkivum) Update(ctx context.Context, exec bob.Executor, s *LocationsArkivumSetter) error { + _, err := LocationsArkivums.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsArkivum record with an executor +func (o *LocationsArkivum) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsArkivums.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsArkivum using the executor +func (o *LocationsArkivum) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsArkivums.Query( + sm.Where(LocationsArkivums.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsArkivumSlice is retrieved from the database +func (o LocationsArkivumSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsArkivums.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsArkivums.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsArkivums.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsArkivums.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsArkivumSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_arkivum", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsArkivumSlice) copyMatchingRows(from ...*LocationsArkivum) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsArkivumSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsArkivums.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsArkivum: + o.copyMatchingRows(retrieved) + case []*LocationsArkivum: + o.copyMatchingRows(retrieved...) + case LocationsArkivumSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsArkivum or a slice of LocationsArkivum + // then run the AfterUpdateHooks on the slice + _, err = LocationsArkivums.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsArkivumSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsArkivums.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsArkivum: + o.copyMatchingRows(retrieved) + case []*LocationsArkivum: + o.copyMatchingRows(retrieved...) + case LocationsArkivumSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsArkivum or a slice of LocationsArkivum + // then run the AfterDeleteHooks on the slice + _, err = LocationsArkivums.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsArkivumSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsArkivumSetter) error { + _, err := LocationsArkivums.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsArkivumSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsArkivums.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsArkivumSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsArkivums.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsArkivum) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsArkivumSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsArkivumSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsArkivum0 *LocationsArkivum, locationsSpace1 *LocationsSpace) (*LocationsArkivum, error) { + setter := &LocationsArkivumSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsArkivum0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsArkivumSpaceLocationsSpace0: %w", err) + } + + return locationsArkivum0, nil +} + +func (locationsArkivum0 *LocationsArkivum) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsArkivumSpaceLocationsSpace0(ctx, exec, 1, locationsArkivum0, locationsSpace1) + if err != nil { + return err + } + + locationsArkivum0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsArkivum = locationsArkivum0 + + return nil +} + +func (locationsArkivum0 *LocationsArkivum) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsArkivumSpaceLocationsSpace0(ctx, exec, 1, locationsArkivum0, locationsSpace1) + if err != nil { + return err + } + + locationsArkivum0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsArkivum = locationsArkivum0 + + return nil +} + +type locationsArkivumWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Host mysql.WhereMod[Q, string] + RemoteUser mysql.WhereNullMod[Q, string] + RemoteName mysql.WhereNullMod[Q, string] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsArkivumWhere[Q]) AliasedAs(alias string) locationsArkivumWhere[Q] { + return buildLocationsArkivumWhere[Q](buildLocationsArkivumColumns(alias)) +} + +func buildLocationsArkivumWhere[Q mysql.Filterable](cols locationsArkivumColumns) locationsArkivumWhere[Q] { + return locationsArkivumWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Host: mysql.Where[Q, string](cols.Host), + RemoteUser: mysql.WhereNull[Q, string](cols.RemoteUser), + RemoteName: mysql.WhereNull[Q, string](cols.RemoteName), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsArkivum) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsArkivum cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsArkivum = o + } + return nil + default: + return fmt.Errorf("locationsArkivum has no relationship %q", name) + } +} + +type locationsArkivumPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsArkivumPreloader() locationsArkivumPreloader { + return locationsArkivumPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsArkivums, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsArkivumThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsArkivumThenLoader[Q orm.Loadable]() locationsArkivumThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsArkivumThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsArkivum's SpaceLocationsSpace into the .R struct +func (o *LocationsArkivum) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsArkivum = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsArkivum's SpaceLocationsSpace into the .R struct +func (os LocationsArkivumSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsArkivum = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsArkivumJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsArkivumJoins[Q]) aliasedAs(alias string) locationsArkivumJoins[Q] { + return buildLocationsArkivumJoins[Q](buildLocationsArkivumColumns(alias), j.typ) +} + +func buildLocationsArkivumJoins[Q dialect.Joinable](cols locationsArkivumColumns, typ string) locationsArkivumJoins[Q] { + return locationsArkivumJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_async.bob.go b/database/storage_service/models/locations_async.bob.go new file mode 100644 index 0000000..86805cb --- /dev/null +++ b/database/storage_service/models/locations_async.bob.go @@ -0,0 +1,517 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "io" + "time" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" +) + +// LocationsAsync is an object representing the database table. +type LocationsAsync struct { + ID int32 `db:"id,pk,autoincr" ` + Completed bool `db:"completed" ` + WasError bool `db:"was_error" ` + Result null.Val[[]byte] `db:"result" ` + Error null.Val[[]byte] `db:"error" ` + CreatedTime time.Time `db:"created_time" ` + UpdatedTime time.Time `db:"updated_time" ` + CompletedTime null.Val[time.Time] `db:"completed_time" ` +} + +// LocationsAsyncSlice is an alias for a slice of pointers to LocationsAsync. +// This should almost always be used instead of []*LocationsAsync. +type LocationsAsyncSlice []*LocationsAsync + +// LocationsAsyncs contains methods to work with the locations_async table +var LocationsAsyncs = mysql.NewTablex[*LocationsAsync, LocationsAsyncSlice, *LocationsAsyncSetter]("locations_async", buildLocationsAsyncColumns("locations_async"), []string{"id"}) + +// LocationsAsyncsQuery is a query on the locations_async table +type LocationsAsyncsQuery = *mysql.ViewQuery[*LocationsAsync, LocationsAsyncSlice] + +func buildLocationsAsyncColumns(alias string) locationsAsyncColumns { + return locationsAsyncColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "completed", "was_error", "result", "error", "created_time", "updated_time", "completed_time", + ).WithParent("locations_async"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Completed: mysql.Quote(alias, "completed"), + WasError: mysql.Quote(alias, "was_error"), + Result: mysql.Quote(alias, "result"), + Error: mysql.Quote(alias, "error"), + CreatedTime: mysql.Quote(alias, "created_time"), + UpdatedTime: mysql.Quote(alias, "updated_time"), + CompletedTime: mysql.Quote(alias, "completed_time"), + } +} + +type locationsAsyncColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Completed mysql.Expression + WasError mysql.Expression + Result mysql.Expression + Error mysql.Expression + CreatedTime mysql.Expression + UpdatedTime mysql.Expression + CompletedTime mysql.Expression +} + +func (c locationsAsyncColumns) Alias() string { + return c.tableAlias +} + +func (locationsAsyncColumns) AliasedAs(alias string) locationsAsyncColumns { + return buildLocationsAsyncColumns(alias) +} + +// LocationsAsyncSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsAsyncSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Completed omit.Val[bool] `db:"completed" ` + WasError omit.Val[bool] `db:"was_error" ` + Result omitnull.Val[[]byte] `db:"result" ` + Error omitnull.Val[[]byte] `db:"error" ` + CreatedTime omit.Val[time.Time] `db:"created_time" ` + UpdatedTime omit.Val[time.Time] `db:"updated_time" ` + CompletedTime omitnull.Val[time.Time] `db:"completed_time" ` +} + +func (s LocationsAsyncSetter) SetColumns() []string { + vals := make([]string, 0, 8) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Completed.IsValue() { + vals = append(vals, "completed") + } + if s.WasError.IsValue() { + vals = append(vals, "was_error") + } + if !s.Result.IsUnset() { + vals = append(vals, "result") + } + if !s.Error.IsUnset() { + vals = append(vals, "error") + } + if s.CreatedTime.IsValue() { + vals = append(vals, "created_time") + } + if s.UpdatedTime.IsValue() { + vals = append(vals, "updated_time") + } + if !s.CompletedTime.IsUnset() { + vals = append(vals, "completed_time") + } + return vals +} + +func (s LocationsAsyncSetter) Overwrite(t *LocationsAsync) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Completed.IsValue() { + t.Completed = s.Completed.MustGet() + } + if s.WasError.IsValue() { + t.WasError = s.WasError.MustGet() + } + if !s.Result.IsUnset() { + t.Result = s.Result.MustGetNull() + } + if !s.Error.IsUnset() { + t.Error = s.Error.MustGetNull() + } + if s.CreatedTime.IsValue() { + t.CreatedTime = s.CreatedTime.MustGet() + } + if s.UpdatedTime.IsValue() { + t.UpdatedTime = s.UpdatedTime.MustGet() + } + if !s.CompletedTime.IsUnset() { + t.CompletedTime = s.CompletedTime.MustGetNull() + } +} + +func (s *LocationsAsyncSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsAsyncs.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Completed.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Completed.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.WasError.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.WasError.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Result.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Result.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Error.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Error.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.CreatedTime.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.CreatedTime.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UpdatedTime.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UpdatedTime.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.CompletedTime.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.CompletedTime.MustGetNull()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsAsyncSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_async")...) +} + +func (s LocationsAsyncSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 8) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Completed.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "completed")...), + mysql.Arg(s.Completed), + }}) + } + + if s.WasError.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "was_error")...), + mysql.Arg(s.WasError), + }}) + } + + if !s.Result.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "result")...), + mysql.Arg(s.Result), + }}) + } + + if !s.Error.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "error")...), + mysql.Arg(s.Error), + }}) + } + + if s.CreatedTime.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "created_time")...), + mysql.Arg(s.CreatedTime), + }}) + } + + if s.UpdatedTime.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "updated_time")...), + mysql.Arg(s.UpdatedTime), + }}) + } + + if !s.CompletedTime.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "completed_time")...), + mysql.Arg(s.CompletedTime), + }}) + } + + return exprs +} + +// FindLocationsAsync retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsAsync(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsAsync, error) { + if len(cols) == 0 { + return LocationsAsyncs.Query( + sm.Where(LocationsAsyncs.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsAsyncs.Query( + sm.Where(LocationsAsyncs.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsAsyncs.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsAsyncExists checks the presence of a single record by primary key +func LocationsAsyncExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsAsyncs.Query( + sm.Where(LocationsAsyncs.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsAsync is retrieved from the database +func (o *LocationsAsync) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsAsyncs.AfterSelectHooks.RunHooks(ctx, exec, LocationsAsyncSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsAsyncs.AfterInsertHooks.RunHooks(ctx, exec, LocationsAsyncSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsAsyncs.AfterUpdateHooks.RunHooks(ctx, exec, LocationsAsyncSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsAsyncs.AfterDeleteHooks.RunHooks(ctx, exec, LocationsAsyncSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsAsync +func (o *LocationsAsync) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsAsync) pkEQ() dialect.Expression { + return mysql.Quote("locations_async", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsAsync +func (o *LocationsAsync) Update(ctx context.Context, exec bob.Executor, s *LocationsAsyncSetter) error { + _, err := LocationsAsyncs.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsAsync record with an executor +func (o *LocationsAsync) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsAsyncs.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsAsync using the executor +func (o *LocationsAsync) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsAsyncs.Query( + sm.Where(LocationsAsyncs.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsAsyncSlice is retrieved from the database +func (o LocationsAsyncSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsAsyncs.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsAsyncs.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsAsyncs.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsAsyncs.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsAsyncSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_async", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsAsyncSlice) copyMatchingRows(from ...*LocationsAsync) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsAsyncSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsAsyncs.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsAsync: + o.copyMatchingRows(retrieved) + case []*LocationsAsync: + o.copyMatchingRows(retrieved...) + case LocationsAsyncSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsAsync or a slice of LocationsAsync + // then run the AfterUpdateHooks on the slice + _, err = LocationsAsyncs.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsAsyncSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsAsyncs.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsAsync: + o.copyMatchingRows(retrieved) + case []*LocationsAsync: + o.copyMatchingRows(retrieved...) + case LocationsAsyncSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsAsync or a slice of LocationsAsync + // then run the AfterDeleteHooks on the slice + _, err = LocationsAsyncs.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsAsyncSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsAsyncSetter) error { + _, err := LocationsAsyncs.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsAsyncSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsAsyncs.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsAsyncSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsAsyncs.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +type locationsAsyncWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Completed mysql.WhereMod[Q, bool] + WasError mysql.WhereMod[Q, bool] + Result mysql.WhereNullMod[Q, []byte] + Error mysql.WhereNullMod[Q, []byte] + CreatedTime mysql.WhereMod[Q, time.Time] + UpdatedTime mysql.WhereMod[Q, time.Time] + CompletedTime mysql.WhereNullMod[Q, time.Time] +} + +func (locationsAsyncWhere[Q]) AliasedAs(alias string) locationsAsyncWhere[Q] { + return buildLocationsAsyncWhere[Q](buildLocationsAsyncColumns(alias)) +} + +func buildLocationsAsyncWhere[Q mysql.Filterable](cols locationsAsyncColumns) locationsAsyncWhere[Q] { + return locationsAsyncWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Completed: mysql.Where[Q, bool](cols.Completed), + WasError: mysql.Where[Q, bool](cols.WasError), + Result: mysql.WhereNull[Q, []byte](cols.Result), + Error: mysql.WhereNull[Q, []byte](cols.Error), + CreatedTime: mysql.Where[Q, time.Time](cols.CreatedTime), + UpdatedTime: mysql.Where[Q, time.Time](cols.UpdatedTime), + CompletedTime: mysql.WhereNull[Q, time.Time](cols.CompletedTime), + } +} diff --git a/database/storage_service/models/locations_callback.bob.go b/database/storage_service/models/locations_callback.bob.go new file mode 100644 index 0000000..e0d87f6 --- /dev/null +++ b/database/storage_service/models/locations_callback.bob.go @@ -0,0 +1,540 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" +) + +// LocationsCallback is an object representing the database table. +type LocationsCallback struct { + ID int32 `db:"id,pk,autoincr" ` + UUID string `db:"uuid" ` + URI string `db:"uri" ` + Event string `db:"event" ` + Method string `db:"method" ` + ExpectedStatus int32 `db:"expected_status" ` + Enabled bool `db:"enabled" ` + Body null.Val[string] `db:"body" ` + Headers null.Val[string] `db:"headers" ` +} + +// LocationsCallbackSlice is an alias for a slice of pointers to LocationsCallback. +// This should almost always be used instead of []*LocationsCallback. +type LocationsCallbackSlice []*LocationsCallback + +// LocationsCallbacks contains methods to work with the locations_callback table +var LocationsCallbacks = mysql.NewTablex[*LocationsCallback, LocationsCallbackSlice, *LocationsCallbackSetter]("locations_callback", buildLocationsCallbackColumns("locations_callback"), []string{"id"}) + +// LocationsCallbacksQuery is a query on the locations_callback table +type LocationsCallbacksQuery = *mysql.ViewQuery[*LocationsCallback, LocationsCallbackSlice] + +func buildLocationsCallbackColumns(alias string) locationsCallbackColumns { + return locationsCallbackColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "uuid", "uri", "event", "method", "expected_status", "enabled", "body", "headers", + ).WithParent("locations_callback"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UUID: mysql.Quote(alias, "uuid"), + URI: mysql.Quote(alias, "uri"), + Event: mysql.Quote(alias, "event"), + Method: mysql.Quote(alias, "method"), + ExpectedStatus: mysql.Quote(alias, "expected_status"), + Enabled: mysql.Quote(alias, "enabled"), + Body: mysql.Quote(alias, "body"), + Headers: mysql.Quote(alias, "headers"), + } +} + +type locationsCallbackColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UUID mysql.Expression + URI mysql.Expression + Event mysql.Expression + Method mysql.Expression + ExpectedStatus mysql.Expression + Enabled mysql.Expression + Body mysql.Expression + Headers mysql.Expression +} + +func (c locationsCallbackColumns) Alias() string { + return c.tableAlias +} + +func (locationsCallbackColumns) AliasedAs(alias string) locationsCallbackColumns { + return buildLocationsCallbackColumns(alias) +} + +// LocationsCallbackSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsCallbackSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UUID omit.Val[string] `db:"uuid" ` + URI omit.Val[string] `db:"uri" ` + Event omit.Val[string] `db:"event" ` + Method omit.Val[string] `db:"method" ` + ExpectedStatus omit.Val[int32] `db:"expected_status" ` + Enabled omit.Val[bool] `db:"enabled" ` + Body omitnull.Val[string] `db:"body" ` + Headers omitnull.Val[string] `db:"headers" ` +} + +func (s LocationsCallbackSetter) SetColumns() []string { + vals := make([]string, 0, 9) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UUID.IsValue() { + vals = append(vals, "uuid") + } + if s.URI.IsValue() { + vals = append(vals, "uri") + } + if s.Event.IsValue() { + vals = append(vals, "event") + } + if s.Method.IsValue() { + vals = append(vals, "method") + } + if s.ExpectedStatus.IsValue() { + vals = append(vals, "expected_status") + } + if s.Enabled.IsValue() { + vals = append(vals, "enabled") + } + if !s.Body.IsUnset() { + vals = append(vals, "body") + } + if !s.Headers.IsUnset() { + vals = append(vals, "headers") + } + return vals +} + +func (s LocationsCallbackSetter) Overwrite(t *LocationsCallback) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UUID.IsValue() { + t.UUID = s.UUID.MustGet() + } + if s.URI.IsValue() { + t.URI = s.URI.MustGet() + } + if s.Event.IsValue() { + t.Event = s.Event.MustGet() + } + if s.Method.IsValue() { + t.Method = s.Method.MustGet() + } + if s.ExpectedStatus.IsValue() { + t.ExpectedStatus = s.ExpectedStatus.MustGet() + } + if s.Enabled.IsValue() { + t.Enabled = s.Enabled.MustGet() + } + if !s.Body.IsUnset() { + t.Body = s.Body.MustGetNull() + } + if !s.Headers.IsUnset() { + t.Headers = s.Headers.MustGetNull() + } +} + +func (s *LocationsCallbackSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsCallbacks.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UUID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UUID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.URI.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.URI.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Event.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Event.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Method.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Method.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ExpectedStatus.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ExpectedStatus.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Enabled.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Enabled.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Body.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Body.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Headers.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Headers.MustGetNull()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsCallbackSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_callback")...) +} + +func (s LocationsCallbackSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 9) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UUID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uuid")...), + mysql.Arg(s.UUID), + }}) + } + + if s.URI.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uri")...), + mysql.Arg(s.URI), + }}) + } + + if s.Event.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "event")...), + mysql.Arg(s.Event), + }}) + } + + if s.Method.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "method")...), + mysql.Arg(s.Method), + }}) + } + + if s.ExpectedStatus.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "expected_status")...), + mysql.Arg(s.ExpectedStatus), + }}) + } + + if s.Enabled.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "enabled")...), + mysql.Arg(s.Enabled), + }}) + } + + if !s.Body.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "body")...), + mysql.Arg(s.Body), + }}) + } + + if !s.Headers.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "headers")...), + mysql.Arg(s.Headers), + }}) + } + + return exprs +} + +// FindLocationsCallback retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsCallback(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsCallback, error) { + if len(cols) == 0 { + return LocationsCallbacks.Query( + sm.Where(LocationsCallbacks.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsCallbacks.Query( + sm.Where(LocationsCallbacks.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsCallbacks.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsCallbackExists checks the presence of a single record by primary key +func LocationsCallbackExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsCallbacks.Query( + sm.Where(LocationsCallbacks.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsCallback is retrieved from the database +func (o *LocationsCallback) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsCallbacks.AfterSelectHooks.RunHooks(ctx, exec, LocationsCallbackSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsCallbacks.AfterInsertHooks.RunHooks(ctx, exec, LocationsCallbackSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsCallbacks.AfterUpdateHooks.RunHooks(ctx, exec, LocationsCallbackSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsCallbacks.AfterDeleteHooks.RunHooks(ctx, exec, LocationsCallbackSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsCallback +func (o *LocationsCallback) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsCallback) pkEQ() dialect.Expression { + return mysql.Quote("locations_callback", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsCallback +func (o *LocationsCallback) Update(ctx context.Context, exec bob.Executor, s *LocationsCallbackSetter) error { + _, err := LocationsCallbacks.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsCallback record with an executor +func (o *LocationsCallback) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsCallbacks.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsCallback using the executor +func (o *LocationsCallback) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsCallbacks.Query( + sm.Where(LocationsCallbacks.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsCallbackSlice is retrieved from the database +func (o LocationsCallbackSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsCallbacks.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsCallbacks.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsCallbacks.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsCallbacks.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsCallbackSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_callback", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsCallbackSlice) copyMatchingRows(from ...*LocationsCallback) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsCallbackSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsCallbacks.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsCallback: + o.copyMatchingRows(retrieved) + case []*LocationsCallback: + o.copyMatchingRows(retrieved...) + case LocationsCallbackSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsCallback or a slice of LocationsCallback + // then run the AfterUpdateHooks on the slice + _, err = LocationsCallbacks.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsCallbackSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsCallbacks.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsCallback: + o.copyMatchingRows(retrieved) + case []*LocationsCallback: + o.copyMatchingRows(retrieved...) + case LocationsCallbackSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsCallback or a slice of LocationsCallback + // then run the AfterDeleteHooks on the slice + _, err = LocationsCallbacks.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsCallbackSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsCallbackSetter) error { + _, err := LocationsCallbacks.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsCallbackSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsCallbacks.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsCallbackSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsCallbacks.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +type locationsCallbackWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UUID mysql.WhereMod[Q, string] + URI mysql.WhereMod[Q, string] + Event mysql.WhereMod[Q, string] + Method mysql.WhereMod[Q, string] + ExpectedStatus mysql.WhereMod[Q, int32] + Enabled mysql.WhereMod[Q, bool] + Body mysql.WhereNullMod[Q, string] + Headers mysql.WhereNullMod[Q, string] +} + +func (locationsCallbackWhere[Q]) AliasedAs(alias string) locationsCallbackWhere[Q] { + return buildLocationsCallbackWhere[Q](buildLocationsCallbackColumns(alias)) +} + +func buildLocationsCallbackWhere[Q mysql.Filterable](cols locationsCallbackColumns) locationsCallbackWhere[Q] { + return locationsCallbackWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UUID: mysql.Where[Q, string](cols.UUID), + URI: mysql.Where[Q, string](cols.URI), + Event: mysql.Where[Q, string](cols.Event), + Method: mysql.Where[Q, string](cols.Method), + ExpectedStatus: mysql.Where[Q, int32](cols.ExpectedStatus), + Enabled: mysql.Where[Q, bool](cols.Enabled), + Body: mysql.WhereNull[Q, string](cols.Body), + Headers: mysql.WhereNull[Q, string](cols.Headers), + } +} diff --git a/database/storage_service/models/locations_dataverse.bob.go b/database/storage_service/models/locations_dataverse.bob.go new file mode 100644 index 0000000..5842b71 --- /dev/null +++ b/database/storage_service/models/locations_dataverse.bob.go @@ -0,0 +1,712 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsDataverse is an object representing the database table. +type LocationsDataverse struct { + ID int32 `db:"id,pk,autoincr" ` + Host string `db:"host" ` + APIKey string `db:"api_key" ` + AgentName string `db:"agent_name" ` + AgentType string `db:"agent_type" ` + AgentIdentifier string `db:"agent_identifier" ` + SpaceID string `db:"space_id" ` + + R locationsDataverseR `db:"-" ` +} + +// LocationsDataverseSlice is an alias for a slice of pointers to LocationsDataverse. +// This should almost always be used instead of []*LocationsDataverse. +type LocationsDataverseSlice []*LocationsDataverse + +// LocationsDataverses contains methods to work with the locations_dataverse table +var LocationsDataverses = mysql.NewTablex[*LocationsDataverse, LocationsDataverseSlice, *LocationsDataverseSetter]("locations_dataverse", buildLocationsDataverseColumns("locations_dataverse"), []string{"id"}, []string{"space_id"}) + +// LocationsDataversesQuery is a query on the locations_dataverse table +type LocationsDataversesQuery = *mysql.ViewQuery[*LocationsDataverse, LocationsDataverseSlice] + +// locationsDataverseR is where relationships are stored. +type locationsDataverseR struct { + SpaceLocationsSpace *LocationsSpace // locations_dataverse_space_id_1b94d732_fk_locations_space_uuid +} + +func buildLocationsDataverseColumns(alias string) locationsDataverseColumns { + return locationsDataverseColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "host", "api_key", "agent_name", "agent_type", "agent_identifier", "space_id", + ).WithParent("locations_dataverse"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Host: mysql.Quote(alias, "host"), + APIKey: mysql.Quote(alias, "api_key"), + AgentName: mysql.Quote(alias, "agent_name"), + AgentType: mysql.Quote(alias, "agent_type"), + AgentIdentifier: mysql.Quote(alias, "agent_identifier"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsDataverseColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Host mysql.Expression + APIKey mysql.Expression + AgentName mysql.Expression + AgentType mysql.Expression + AgentIdentifier mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsDataverseColumns) Alias() string { + return c.tableAlias +} + +func (locationsDataverseColumns) AliasedAs(alias string) locationsDataverseColumns { + return buildLocationsDataverseColumns(alias) +} + +// LocationsDataverseSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsDataverseSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Host omit.Val[string] `db:"host" ` + APIKey omit.Val[string] `db:"api_key" ` + AgentName omit.Val[string] `db:"agent_name" ` + AgentType omit.Val[string] `db:"agent_type" ` + AgentIdentifier omit.Val[string] `db:"agent_identifier" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsDataverseSetter) SetColumns() []string { + vals := make([]string, 0, 7) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Host.IsValue() { + vals = append(vals, "host") + } + if s.APIKey.IsValue() { + vals = append(vals, "api_key") + } + if s.AgentName.IsValue() { + vals = append(vals, "agent_name") + } + if s.AgentType.IsValue() { + vals = append(vals, "agent_type") + } + if s.AgentIdentifier.IsValue() { + vals = append(vals, "agent_identifier") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsDataverseSetter) Overwrite(t *LocationsDataverse) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Host.IsValue() { + t.Host = s.Host.MustGet() + } + if s.APIKey.IsValue() { + t.APIKey = s.APIKey.MustGet() + } + if s.AgentName.IsValue() { + t.AgentName = s.AgentName.MustGet() + } + if s.AgentType.IsValue() { + t.AgentType = s.AgentType.MustGet() + } + if s.AgentIdentifier.IsValue() { + t.AgentIdentifier = s.AgentIdentifier.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsDataverseSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDataverses.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Host.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Host.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.APIKey.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.APIKey.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AgentName.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AgentName.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AgentType.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AgentType.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AgentIdentifier.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AgentIdentifier.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsDataverseSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_dataverse")...) +} + +func (s LocationsDataverseSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 7) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Host.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "host")...), + mysql.Arg(s.Host), + }}) + } + + if s.APIKey.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "api_key")...), + mysql.Arg(s.APIKey), + }}) + } + + if s.AgentName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "agent_name")...), + mysql.Arg(s.AgentName), + }}) + } + + if s.AgentType.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "agent_type")...), + mysql.Arg(s.AgentType), + }}) + } + + if s.AgentIdentifier.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "agent_identifier")...), + mysql.Arg(s.AgentIdentifier), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsDataverse retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsDataverse(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsDataverse, error) { + if len(cols) == 0 { + return LocationsDataverses.Query( + sm.Where(LocationsDataverses.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsDataverses.Query( + sm.Where(LocationsDataverses.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsDataverses.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsDataverseExists checks the presence of a single record by primary key +func LocationsDataverseExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsDataverses.Query( + sm.Where(LocationsDataverses.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsDataverse is retrieved from the database +func (o *LocationsDataverse) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsDataverses.AfterSelectHooks.RunHooks(ctx, exec, LocationsDataverseSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsDataverses.AfterInsertHooks.RunHooks(ctx, exec, LocationsDataverseSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsDataverses.AfterUpdateHooks.RunHooks(ctx, exec, LocationsDataverseSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsDataverses.AfterDeleteHooks.RunHooks(ctx, exec, LocationsDataverseSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsDataverse +func (o *LocationsDataverse) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsDataverse) pkEQ() dialect.Expression { + return mysql.Quote("locations_dataverse", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsDataverse +func (o *LocationsDataverse) Update(ctx context.Context, exec bob.Executor, s *LocationsDataverseSetter) error { + _, err := LocationsDataverses.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsDataverse record with an executor +func (o *LocationsDataverse) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsDataverses.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsDataverse using the executor +func (o *LocationsDataverse) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsDataverses.Query( + sm.Where(LocationsDataverses.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsDataverseSlice is retrieved from the database +func (o LocationsDataverseSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsDataverses.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsDataverses.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsDataverses.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsDataverses.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsDataverseSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_dataverse", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsDataverseSlice) copyMatchingRows(from ...*LocationsDataverse) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsDataverseSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDataverses.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsDataverse: + o.copyMatchingRows(retrieved) + case []*LocationsDataverse: + o.copyMatchingRows(retrieved...) + case LocationsDataverseSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsDataverse or a slice of LocationsDataverse + // then run the AfterUpdateHooks on the slice + _, err = LocationsDataverses.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsDataverseSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDataverses.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsDataverse: + o.copyMatchingRows(retrieved) + case []*LocationsDataverse: + o.copyMatchingRows(retrieved...) + case LocationsDataverseSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsDataverse or a slice of LocationsDataverse + // then run the AfterDeleteHooks on the slice + _, err = LocationsDataverses.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsDataverseSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsDataverseSetter) error { + _, err := LocationsDataverses.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsDataverseSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsDataverses.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsDataverseSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsDataverses.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsDataverse) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsDataverseSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsDataverseSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsDataverse0 *LocationsDataverse, locationsSpace1 *LocationsSpace) (*LocationsDataverse, error) { + setter := &LocationsDataverseSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsDataverse0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsDataverseSpaceLocationsSpace0: %w", err) + } + + return locationsDataverse0, nil +} + +func (locationsDataverse0 *LocationsDataverse) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsDataverseSpaceLocationsSpace0(ctx, exec, 1, locationsDataverse0, locationsSpace1) + if err != nil { + return err + } + + locationsDataverse0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsDataverse = locationsDataverse0 + + return nil +} + +func (locationsDataverse0 *LocationsDataverse) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsDataverseSpaceLocationsSpace0(ctx, exec, 1, locationsDataverse0, locationsSpace1) + if err != nil { + return err + } + + locationsDataverse0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsDataverse = locationsDataverse0 + + return nil +} + +type locationsDataverseWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Host mysql.WhereMod[Q, string] + APIKey mysql.WhereMod[Q, string] + AgentName mysql.WhereMod[Q, string] + AgentType mysql.WhereMod[Q, string] + AgentIdentifier mysql.WhereMod[Q, string] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsDataverseWhere[Q]) AliasedAs(alias string) locationsDataverseWhere[Q] { + return buildLocationsDataverseWhere[Q](buildLocationsDataverseColumns(alias)) +} + +func buildLocationsDataverseWhere[Q mysql.Filterable](cols locationsDataverseColumns) locationsDataverseWhere[Q] { + return locationsDataverseWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Host: mysql.Where[Q, string](cols.Host), + APIKey: mysql.Where[Q, string](cols.APIKey), + AgentName: mysql.Where[Q, string](cols.AgentName), + AgentType: mysql.Where[Q, string](cols.AgentType), + AgentIdentifier: mysql.Where[Q, string](cols.AgentIdentifier), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsDataverse) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsDataverse cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsDataverse = o + } + return nil + default: + return fmt.Errorf("locationsDataverse has no relationship %q", name) + } +} + +type locationsDataversePreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsDataversePreloader() locationsDataversePreloader { + return locationsDataversePreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsDataverses, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsDataverseThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsDataverseThenLoader[Q orm.Loadable]() locationsDataverseThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsDataverseThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsDataverse's SpaceLocationsSpace into the .R struct +func (o *LocationsDataverse) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsDataverse = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsDataverse's SpaceLocationsSpace into the .R struct +func (os LocationsDataverseSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsDataverse = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsDataverseJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsDataverseJoins[Q]) aliasedAs(alias string) locationsDataverseJoins[Q] { + return buildLocationsDataverseJoins[Q](buildLocationsDataverseColumns(alias), j.typ) +} + +func buildLocationsDataverseJoins[Q dialect.Joinable](cols locationsDataverseColumns, typ string) locationsDataverseJoins[Q] { + return locationsDataverseJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_dspace.bob.go b/database/storage_service/models/locations_dspace.bob.go new file mode 100644 index 0000000..1bbb03c --- /dev/null +++ b/database/storage_service/models/locations_dspace.bob.go @@ -0,0 +1,714 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsDspace is an object representing the database table. +type LocationsDspace struct { + ID int32 `db:"id,pk,autoincr" ` + SDIri string `db:"sd_iri" ` + User string `db:"user" ` + Password string `db:"password" ` + SpaceID string `db:"space_id" ` + MetadataPolicy null.Val[string] `db:"metadata_policy" ` + ArchiveFormat string `db:"archive_format" ` + + R locationsDspaceR `db:"-" ` +} + +// LocationsDspaceSlice is an alias for a slice of pointers to LocationsDspace. +// This should almost always be used instead of []*LocationsDspace. +type LocationsDspaceSlice []*LocationsDspace + +// LocationsDspaces contains methods to work with the locations_dspace table +var LocationsDspaces = mysql.NewTablex[*LocationsDspace, LocationsDspaceSlice, *LocationsDspaceSetter]("locations_dspace", buildLocationsDspaceColumns("locations_dspace"), []string{"id"}, []string{"space_id"}) + +// LocationsDspacesQuery is a query on the locations_dspace table +type LocationsDspacesQuery = *mysql.ViewQuery[*LocationsDspace, LocationsDspaceSlice] + +// locationsDspaceR is where relationships are stored. +type locationsDspaceR struct { + SpaceLocationsSpace *LocationsSpace // locations_dspace_space_id_e1c12ce1_fk_locations_space_uuid +} + +func buildLocationsDspaceColumns(alias string) locationsDspaceColumns { + return locationsDspaceColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "sd_iri", "user", "password", "space_id", "metadata_policy", "archive_format", + ).WithParent("locations_dspace"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + SDIri: mysql.Quote(alias, "sd_iri"), + User: mysql.Quote(alias, "user"), + Password: mysql.Quote(alias, "password"), + SpaceID: mysql.Quote(alias, "space_id"), + MetadataPolicy: mysql.Quote(alias, "metadata_policy"), + ArchiveFormat: mysql.Quote(alias, "archive_format"), + } +} + +type locationsDspaceColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + SDIri mysql.Expression + User mysql.Expression + Password mysql.Expression + SpaceID mysql.Expression + MetadataPolicy mysql.Expression + ArchiveFormat mysql.Expression +} + +func (c locationsDspaceColumns) Alias() string { + return c.tableAlias +} + +func (locationsDspaceColumns) AliasedAs(alias string) locationsDspaceColumns { + return buildLocationsDspaceColumns(alias) +} + +// LocationsDspaceSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsDspaceSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + SDIri omit.Val[string] `db:"sd_iri" ` + User omit.Val[string] `db:"user" ` + Password omit.Val[string] `db:"password" ` + SpaceID omit.Val[string] `db:"space_id" ` + MetadataPolicy omitnull.Val[string] `db:"metadata_policy" ` + ArchiveFormat omit.Val[string] `db:"archive_format" ` +} + +func (s LocationsDspaceSetter) SetColumns() []string { + vals := make([]string, 0, 7) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.SDIri.IsValue() { + vals = append(vals, "sd_iri") + } + if s.User.IsValue() { + vals = append(vals, "user") + } + if s.Password.IsValue() { + vals = append(vals, "password") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + if !s.MetadataPolicy.IsUnset() { + vals = append(vals, "metadata_policy") + } + if s.ArchiveFormat.IsValue() { + vals = append(vals, "archive_format") + } + return vals +} + +func (s LocationsDspaceSetter) Overwrite(t *LocationsDspace) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.SDIri.IsValue() { + t.SDIri = s.SDIri.MustGet() + } + if s.User.IsValue() { + t.User = s.User.MustGet() + } + if s.Password.IsValue() { + t.Password = s.Password.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } + if !s.MetadataPolicy.IsUnset() { + t.MetadataPolicy = s.MetadataPolicy.MustGetNull() + } + if s.ArchiveFormat.IsValue() { + t.ArchiveFormat = s.ArchiveFormat.MustGet() + } +} + +func (s *LocationsDspaceSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDspaces.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SDIri.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SDIri.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.User.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.User.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Password.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Password.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.MetadataPolicy.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.MetadataPolicy.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ArchiveFormat.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ArchiveFormat.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsDspaceSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_dspace")...) +} + +func (s LocationsDspaceSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 7) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.SDIri.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "sd_iri")...), + mysql.Arg(s.SDIri), + }}) + } + + if s.User.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "user")...), + mysql.Arg(s.User), + }}) + } + + if s.Password.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "password")...), + mysql.Arg(s.Password), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + if !s.MetadataPolicy.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "metadata_policy")...), + mysql.Arg(s.MetadataPolicy), + }}) + } + + if s.ArchiveFormat.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "archive_format")...), + mysql.Arg(s.ArchiveFormat), + }}) + } + + return exprs +} + +// FindLocationsDspace retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsDspace(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsDspace, error) { + if len(cols) == 0 { + return LocationsDspaces.Query( + sm.Where(LocationsDspaces.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsDspaces.Query( + sm.Where(LocationsDspaces.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsDspaces.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsDspaceExists checks the presence of a single record by primary key +func LocationsDspaceExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsDspaces.Query( + sm.Where(LocationsDspaces.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsDspace is retrieved from the database +func (o *LocationsDspace) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsDspaces.AfterSelectHooks.RunHooks(ctx, exec, LocationsDspaceSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsDspaces.AfterInsertHooks.RunHooks(ctx, exec, LocationsDspaceSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsDspaces.AfterUpdateHooks.RunHooks(ctx, exec, LocationsDspaceSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsDspaces.AfterDeleteHooks.RunHooks(ctx, exec, LocationsDspaceSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsDspace +func (o *LocationsDspace) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsDspace) pkEQ() dialect.Expression { + return mysql.Quote("locations_dspace", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsDspace +func (o *LocationsDspace) Update(ctx context.Context, exec bob.Executor, s *LocationsDspaceSetter) error { + _, err := LocationsDspaces.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsDspace record with an executor +func (o *LocationsDspace) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsDspaces.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsDspace using the executor +func (o *LocationsDspace) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsDspaces.Query( + sm.Where(LocationsDspaces.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsDspaceSlice is retrieved from the database +func (o LocationsDspaceSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsDspaces.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsDspaces.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsDspaces.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsDspaces.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsDspaceSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_dspace", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsDspaceSlice) copyMatchingRows(from ...*LocationsDspace) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsDspaceSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDspaces.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsDspace: + o.copyMatchingRows(retrieved) + case []*LocationsDspace: + o.copyMatchingRows(retrieved...) + case LocationsDspaceSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsDspace or a slice of LocationsDspace + // then run the AfterUpdateHooks on the slice + _, err = LocationsDspaces.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsDspaceSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDspaces.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsDspace: + o.copyMatchingRows(retrieved) + case []*LocationsDspace: + o.copyMatchingRows(retrieved...) + case LocationsDspaceSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsDspace or a slice of LocationsDspace + // then run the AfterDeleteHooks on the slice + _, err = LocationsDspaces.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsDspaceSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsDspaceSetter) error { + _, err := LocationsDspaces.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsDspaceSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsDspaces.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsDspaceSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsDspaces.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsDspace) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsDspaceSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsDspaceSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsDspace0 *LocationsDspace, locationsSpace1 *LocationsSpace) (*LocationsDspace, error) { + setter := &LocationsDspaceSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsDspace0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsDspaceSpaceLocationsSpace0: %w", err) + } + + return locationsDspace0, nil +} + +func (locationsDspace0 *LocationsDspace) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsDspaceSpaceLocationsSpace0(ctx, exec, 1, locationsDspace0, locationsSpace1) + if err != nil { + return err + } + + locationsDspace0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsDspace = locationsDspace0 + + return nil +} + +func (locationsDspace0 *LocationsDspace) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsDspaceSpaceLocationsSpace0(ctx, exec, 1, locationsDspace0, locationsSpace1) + if err != nil { + return err + } + + locationsDspace0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsDspace = locationsDspace0 + + return nil +} + +type locationsDspaceWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + SDIri mysql.WhereMod[Q, string] + User mysql.WhereMod[Q, string] + Password mysql.WhereMod[Q, string] + SpaceID mysql.WhereMod[Q, string] + MetadataPolicy mysql.WhereNullMod[Q, string] + ArchiveFormat mysql.WhereMod[Q, string] +} + +func (locationsDspaceWhere[Q]) AliasedAs(alias string) locationsDspaceWhere[Q] { + return buildLocationsDspaceWhere[Q](buildLocationsDspaceColumns(alias)) +} + +func buildLocationsDspaceWhere[Q mysql.Filterable](cols locationsDspaceColumns) locationsDspaceWhere[Q] { + return locationsDspaceWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + SDIri: mysql.Where[Q, string](cols.SDIri), + User: mysql.Where[Q, string](cols.User), + Password: mysql.Where[Q, string](cols.Password), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + MetadataPolicy: mysql.WhereNull[Q, string](cols.MetadataPolicy), + ArchiveFormat: mysql.Where[Q, string](cols.ArchiveFormat), + } +} + +func (o *LocationsDspace) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsDspace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsDspace = o + } + return nil + default: + return fmt.Errorf("locationsDspace has no relationship %q", name) + } +} + +type locationsDspacePreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsDspacePreloader() locationsDspacePreloader { + return locationsDspacePreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsDspaces, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsDspaceThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsDspaceThenLoader[Q orm.Loadable]() locationsDspaceThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsDspaceThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsDspace's SpaceLocationsSpace into the .R struct +func (o *LocationsDspace) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsDspace = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsDspace's SpaceLocationsSpace into the .R struct +func (os LocationsDspaceSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsDspace = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsDspaceJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsDspaceJoins[Q]) aliasedAs(alias string) locationsDspaceJoins[Q] { + return buildLocationsDspaceJoins[Q](buildLocationsDspaceColumns(alias), j.typ) +} + +func buildLocationsDspaceJoins[Q dialect.Joinable](cols locationsDspaceColumns, typ string) locationsDspaceJoins[Q] { + return locationsDspaceJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_dspacerest.bob.go b/database/storage_service/models/locations_dspacerest.bob.go new file mode 100644 index 0000000..c57c864 --- /dev/null +++ b/database/storage_service/models/locations_dspacerest.bob.go @@ -0,0 +1,880 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsDspacerest is an object representing the database table. +type LocationsDspacerest struct { + ID int32 `db:"id,pk,autoincr" ` + DSRestURL string `db:"ds_rest_url" ` + DSUser string `db:"ds_user" ` + DSPassword string `db:"ds_password" ` + DSDipCollection string `db:"ds_dip_collection" ` + DSAipCollection string `db:"ds_aip_collection" ` + AsURL string `db:"as_url" ` + AsUser string `db:"as_user" ` + AsPassword string `db:"as_password" ` + AsRepository string `db:"as_repository" ` + AsArchivalObject string `db:"as_archival_object" ` + VerifySSL bool `db:"verify_ssl" ` + UploadToTSM bool `db:"upload_to_tsm" ` + SpaceID string `db:"space_id" ` + + R locationsDspacerestR `db:"-" ` +} + +// LocationsDspacerestSlice is an alias for a slice of pointers to LocationsDspacerest. +// This should almost always be used instead of []*LocationsDspacerest. +type LocationsDspacerestSlice []*LocationsDspacerest + +// LocationsDspacerests contains methods to work with the locations_dspacerest table +var LocationsDspacerests = mysql.NewTablex[*LocationsDspacerest, LocationsDspacerestSlice, *LocationsDspacerestSetter]("locations_dspacerest", buildLocationsDspacerestColumns("locations_dspacerest"), []string{"id"}, []string{"space_id"}) + +// LocationsDspacerestsQuery is a query on the locations_dspacerest table +type LocationsDspacerestsQuery = *mysql.ViewQuery[*LocationsDspacerest, LocationsDspacerestSlice] + +// locationsDspacerestR is where relationships are stored. +type locationsDspacerestR struct { + SpaceLocationsSpace *LocationsSpace // locations_dspacerest_space_id_6ae6a82b_fk_locations_space_uuid +} + +func buildLocationsDspacerestColumns(alias string) locationsDspacerestColumns { + return locationsDspacerestColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "ds_rest_url", "ds_user", "ds_password", "ds_dip_collection", "ds_aip_collection", "as_url", "as_user", "as_password", "as_repository", "as_archival_object", "verify_ssl", "upload_to_tsm", "space_id", + ).WithParent("locations_dspacerest"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + DSRestURL: mysql.Quote(alias, "ds_rest_url"), + DSUser: mysql.Quote(alias, "ds_user"), + DSPassword: mysql.Quote(alias, "ds_password"), + DSDipCollection: mysql.Quote(alias, "ds_dip_collection"), + DSAipCollection: mysql.Quote(alias, "ds_aip_collection"), + AsURL: mysql.Quote(alias, "as_url"), + AsUser: mysql.Quote(alias, "as_user"), + AsPassword: mysql.Quote(alias, "as_password"), + AsRepository: mysql.Quote(alias, "as_repository"), + AsArchivalObject: mysql.Quote(alias, "as_archival_object"), + VerifySSL: mysql.Quote(alias, "verify_ssl"), + UploadToTSM: mysql.Quote(alias, "upload_to_tsm"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsDspacerestColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + DSRestURL mysql.Expression + DSUser mysql.Expression + DSPassword mysql.Expression + DSDipCollection mysql.Expression + DSAipCollection mysql.Expression + AsURL mysql.Expression + AsUser mysql.Expression + AsPassword mysql.Expression + AsRepository mysql.Expression + AsArchivalObject mysql.Expression + VerifySSL mysql.Expression + UploadToTSM mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsDspacerestColumns) Alias() string { + return c.tableAlias +} + +func (locationsDspacerestColumns) AliasedAs(alias string) locationsDspacerestColumns { + return buildLocationsDspacerestColumns(alias) +} + +// LocationsDspacerestSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsDspacerestSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + DSRestURL omit.Val[string] `db:"ds_rest_url" ` + DSUser omit.Val[string] `db:"ds_user" ` + DSPassword omit.Val[string] `db:"ds_password" ` + DSDipCollection omit.Val[string] `db:"ds_dip_collection" ` + DSAipCollection omit.Val[string] `db:"ds_aip_collection" ` + AsURL omit.Val[string] `db:"as_url" ` + AsUser omit.Val[string] `db:"as_user" ` + AsPassword omit.Val[string] `db:"as_password" ` + AsRepository omit.Val[string] `db:"as_repository" ` + AsArchivalObject omit.Val[string] `db:"as_archival_object" ` + VerifySSL omit.Val[bool] `db:"verify_ssl" ` + UploadToTSM omit.Val[bool] `db:"upload_to_tsm" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsDspacerestSetter) SetColumns() []string { + vals := make([]string, 0, 14) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.DSRestURL.IsValue() { + vals = append(vals, "ds_rest_url") + } + if s.DSUser.IsValue() { + vals = append(vals, "ds_user") + } + if s.DSPassword.IsValue() { + vals = append(vals, "ds_password") + } + if s.DSDipCollection.IsValue() { + vals = append(vals, "ds_dip_collection") + } + if s.DSAipCollection.IsValue() { + vals = append(vals, "ds_aip_collection") + } + if s.AsURL.IsValue() { + vals = append(vals, "as_url") + } + if s.AsUser.IsValue() { + vals = append(vals, "as_user") + } + if s.AsPassword.IsValue() { + vals = append(vals, "as_password") + } + if s.AsRepository.IsValue() { + vals = append(vals, "as_repository") + } + if s.AsArchivalObject.IsValue() { + vals = append(vals, "as_archival_object") + } + if s.VerifySSL.IsValue() { + vals = append(vals, "verify_ssl") + } + if s.UploadToTSM.IsValue() { + vals = append(vals, "upload_to_tsm") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsDspacerestSetter) Overwrite(t *LocationsDspacerest) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.DSRestURL.IsValue() { + t.DSRestURL = s.DSRestURL.MustGet() + } + if s.DSUser.IsValue() { + t.DSUser = s.DSUser.MustGet() + } + if s.DSPassword.IsValue() { + t.DSPassword = s.DSPassword.MustGet() + } + if s.DSDipCollection.IsValue() { + t.DSDipCollection = s.DSDipCollection.MustGet() + } + if s.DSAipCollection.IsValue() { + t.DSAipCollection = s.DSAipCollection.MustGet() + } + if s.AsURL.IsValue() { + t.AsURL = s.AsURL.MustGet() + } + if s.AsUser.IsValue() { + t.AsUser = s.AsUser.MustGet() + } + if s.AsPassword.IsValue() { + t.AsPassword = s.AsPassword.MustGet() + } + if s.AsRepository.IsValue() { + t.AsRepository = s.AsRepository.MustGet() + } + if s.AsArchivalObject.IsValue() { + t.AsArchivalObject = s.AsArchivalObject.MustGet() + } + if s.VerifySSL.IsValue() { + t.VerifySSL = s.VerifySSL.MustGet() + } + if s.UploadToTSM.IsValue() { + t.UploadToTSM = s.UploadToTSM.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsDspacerestSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDspacerests.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DSRestURL.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DSRestURL.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DSUser.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DSUser.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DSPassword.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DSPassword.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DSDipCollection.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DSDipCollection.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DSAipCollection.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DSAipCollection.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AsURL.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AsURL.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AsUser.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AsUser.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AsPassword.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AsPassword.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AsRepository.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AsRepository.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AsArchivalObject.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AsArchivalObject.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.VerifySSL.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.VerifySSL.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UploadToTSM.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UploadToTSM.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsDspacerestSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_dspacerest")...) +} + +func (s LocationsDspacerestSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 14) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.DSRestURL.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "ds_rest_url")...), + mysql.Arg(s.DSRestURL), + }}) + } + + if s.DSUser.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "ds_user")...), + mysql.Arg(s.DSUser), + }}) + } + + if s.DSPassword.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "ds_password")...), + mysql.Arg(s.DSPassword), + }}) + } + + if s.DSDipCollection.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "ds_dip_collection")...), + mysql.Arg(s.DSDipCollection), + }}) + } + + if s.DSAipCollection.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "ds_aip_collection")...), + mysql.Arg(s.DSAipCollection), + }}) + } + + if s.AsURL.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "as_url")...), + mysql.Arg(s.AsURL), + }}) + } + + if s.AsUser.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "as_user")...), + mysql.Arg(s.AsUser), + }}) + } + + if s.AsPassword.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "as_password")...), + mysql.Arg(s.AsPassword), + }}) + } + + if s.AsRepository.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "as_repository")...), + mysql.Arg(s.AsRepository), + }}) + } + + if s.AsArchivalObject.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "as_archival_object")...), + mysql.Arg(s.AsArchivalObject), + }}) + } + + if s.VerifySSL.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "verify_ssl")...), + mysql.Arg(s.VerifySSL), + }}) + } + + if s.UploadToTSM.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "upload_to_tsm")...), + mysql.Arg(s.UploadToTSM), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsDspacerest retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsDspacerest(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsDspacerest, error) { + if len(cols) == 0 { + return LocationsDspacerests.Query( + sm.Where(LocationsDspacerests.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsDspacerests.Query( + sm.Where(LocationsDspacerests.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsDspacerests.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsDspacerestExists checks the presence of a single record by primary key +func LocationsDspacerestExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsDspacerests.Query( + sm.Where(LocationsDspacerests.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsDspacerest is retrieved from the database +func (o *LocationsDspacerest) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsDspacerests.AfterSelectHooks.RunHooks(ctx, exec, LocationsDspacerestSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsDspacerests.AfterInsertHooks.RunHooks(ctx, exec, LocationsDspacerestSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsDspacerests.AfterUpdateHooks.RunHooks(ctx, exec, LocationsDspacerestSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsDspacerests.AfterDeleteHooks.RunHooks(ctx, exec, LocationsDspacerestSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsDspacerest +func (o *LocationsDspacerest) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsDspacerest) pkEQ() dialect.Expression { + return mysql.Quote("locations_dspacerest", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsDspacerest +func (o *LocationsDspacerest) Update(ctx context.Context, exec bob.Executor, s *LocationsDspacerestSetter) error { + _, err := LocationsDspacerests.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsDspacerest record with an executor +func (o *LocationsDspacerest) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsDspacerests.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsDspacerest using the executor +func (o *LocationsDspacerest) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsDspacerests.Query( + sm.Where(LocationsDspacerests.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsDspacerestSlice is retrieved from the database +func (o LocationsDspacerestSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsDspacerests.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsDspacerests.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsDspacerests.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsDspacerests.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsDspacerestSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_dspacerest", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsDspacerestSlice) copyMatchingRows(from ...*LocationsDspacerest) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsDspacerestSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDspacerests.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsDspacerest: + o.copyMatchingRows(retrieved) + case []*LocationsDspacerest: + o.copyMatchingRows(retrieved...) + case LocationsDspacerestSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsDspacerest or a slice of LocationsDspacerest + // then run the AfterUpdateHooks on the slice + _, err = LocationsDspacerests.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsDspacerestSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDspacerests.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsDspacerest: + o.copyMatchingRows(retrieved) + case []*LocationsDspacerest: + o.copyMatchingRows(retrieved...) + case LocationsDspacerestSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsDspacerest or a slice of LocationsDspacerest + // then run the AfterDeleteHooks on the slice + _, err = LocationsDspacerests.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsDspacerestSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsDspacerestSetter) error { + _, err := LocationsDspacerests.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsDspacerestSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsDspacerests.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsDspacerestSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsDspacerests.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsDspacerest) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsDspacerestSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsDspacerestSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsDspacerest0 *LocationsDspacerest, locationsSpace1 *LocationsSpace) (*LocationsDspacerest, error) { + setter := &LocationsDspacerestSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsDspacerest0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsDspacerestSpaceLocationsSpace0: %w", err) + } + + return locationsDspacerest0, nil +} + +func (locationsDspacerest0 *LocationsDspacerest) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsDspacerestSpaceLocationsSpace0(ctx, exec, 1, locationsDspacerest0, locationsSpace1) + if err != nil { + return err + } + + locationsDspacerest0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsDspacerest = locationsDspacerest0 + + return nil +} + +func (locationsDspacerest0 *LocationsDspacerest) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsDspacerestSpaceLocationsSpace0(ctx, exec, 1, locationsDspacerest0, locationsSpace1) + if err != nil { + return err + } + + locationsDspacerest0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsDspacerest = locationsDspacerest0 + + return nil +} + +type locationsDspacerestWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + DSRestURL mysql.WhereMod[Q, string] + DSUser mysql.WhereMod[Q, string] + DSPassword mysql.WhereMod[Q, string] + DSDipCollection mysql.WhereMod[Q, string] + DSAipCollection mysql.WhereMod[Q, string] + AsURL mysql.WhereMod[Q, string] + AsUser mysql.WhereMod[Q, string] + AsPassword mysql.WhereMod[Q, string] + AsRepository mysql.WhereMod[Q, string] + AsArchivalObject mysql.WhereMod[Q, string] + VerifySSL mysql.WhereMod[Q, bool] + UploadToTSM mysql.WhereMod[Q, bool] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsDspacerestWhere[Q]) AliasedAs(alias string) locationsDspacerestWhere[Q] { + return buildLocationsDspacerestWhere[Q](buildLocationsDspacerestColumns(alias)) +} + +func buildLocationsDspacerestWhere[Q mysql.Filterable](cols locationsDspacerestColumns) locationsDspacerestWhere[Q] { + return locationsDspacerestWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + DSRestURL: mysql.Where[Q, string](cols.DSRestURL), + DSUser: mysql.Where[Q, string](cols.DSUser), + DSPassword: mysql.Where[Q, string](cols.DSPassword), + DSDipCollection: mysql.Where[Q, string](cols.DSDipCollection), + DSAipCollection: mysql.Where[Q, string](cols.DSAipCollection), + AsURL: mysql.Where[Q, string](cols.AsURL), + AsUser: mysql.Where[Q, string](cols.AsUser), + AsPassword: mysql.Where[Q, string](cols.AsPassword), + AsRepository: mysql.Where[Q, string](cols.AsRepository), + AsArchivalObject: mysql.Where[Q, string](cols.AsArchivalObject), + VerifySSL: mysql.Where[Q, bool](cols.VerifySSL), + UploadToTSM: mysql.Where[Q, bool](cols.UploadToTSM), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsDspacerest) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsDspacerest cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsDspacerest = o + } + return nil + default: + return fmt.Errorf("locationsDspacerest has no relationship %q", name) + } +} + +type locationsDspacerestPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsDspacerestPreloader() locationsDspacerestPreloader { + return locationsDspacerestPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsDspacerests, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsDspacerestThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsDspacerestThenLoader[Q orm.Loadable]() locationsDspacerestThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsDspacerestThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsDspacerest's SpaceLocationsSpace into the .R struct +func (o *LocationsDspacerest) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsDspacerest = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsDspacerest's SpaceLocationsSpace into the .R struct +func (os LocationsDspacerestSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsDspacerest = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsDspacerestJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsDspacerestJoins[Q]) aliasedAs(alias string) locationsDspacerestJoins[Q] { + return buildLocationsDspacerestJoins[Q](buildLocationsDspacerestColumns(alias), j.typ) +} + +func buildLocationsDspacerestJoins[Q dialect.Joinable](cols locationsDspacerestColumns, typ string) locationsDspacerestJoins[Q] { + return locationsDspacerestJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_duracloud.bob.go b/database/storage_service/models/locations_duracloud.bob.go new file mode 100644 index 0000000..c4fa324 --- /dev/null +++ b/database/storage_service/models/locations_duracloud.bob.go @@ -0,0 +1,688 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsDuracloud is an object representing the database table. +type LocationsDuracloud struct { + ID int32 `db:"id,pk,autoincr" ` + Host string `db:"host" ` + User string `db:"user" ` + Password string `db:"password" ` + Duraspace string `db:"duraspace" ` + SpaceID string `db:"space_id" ` + + R locationsDuracloudR `db:"-" ` +} + +// LocationsDuracloudSlice is an alias for a slice of pointers to LocationsDuracloud. +// This should almost always be used instead of []*LocationsDuracloud. +type LocationsDuracloudSlice []*LocationsDuracloud + +// LocationsDuraclouds contains methods to work with the locations_duracloud table +var LocationsDuraclouds = mysql.NewTablex[*LocationsDuracloud, LocationsDuracloudSlice, *LocationsDuracloudSetter]("locations_duracloud", buildLocationsDuracloudColumns("locations_duracloud"), []string{"id"}, []string{"space_id"}) + +// LocationsDuracloudsQuery is a query on the locations_duracloud table +type LocationsDuracloudsQuery = *mysql.ViewQuery[*LocationsDuracloud, LocationsDuracloudSlice] + +// locationsDuracloudR is where relationships are stored. +type locationsDuracloudR struct { + SpaceLocationsSpace *LocationsSpace // locations_duracloud_space_id_753df0f2_fk_locations_space_uuid +} + +func buildLocationsDuracloudColumns(alias string) locationsDuracloudColumns { + return locationsDuracloudColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "host", "user", "password", "duraspace", "space_id", + ).WithParent("locations_duracloud"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Host: mysql.Quote(alias, "host"), + User: mysql.Quote(alias, "user"), + Password: mysql.Quote(alias, "password"), + Duraspace: mysql.Quote(alias, "duraspace"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsDuracloudColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Host mysql.Expression + User mysql.Expression + Password mysql.Expression + Duraspace mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsDuracloudColumns) Alias() string { + return c.tableAlias +} + +func (locationsDuracloudColumns) AliasedAs(alias string) locationsDuracloudColumns { + return buildLocationsDuracloudColumns(alias) +} + +// LocationsDuracloudSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsDuracloudSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Host omit.Val[string] `db:"host" ` + User omit.Val[string] `db:"user" ` + Password omit.Val[string] `db:"password" ` + Duraspace omit.Val[string] `db:"duraspace" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsDuracloudSetter) SetColumns() []string { + vals := make([]string, 0, 6) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Host.IsValue() { + vals = append(vals, "host") + } + if s.User.IsValue() { + vals = append(vals, "user") + } + if s.Password.IsValue() { + vals = append(vals, "password") + } + if s.Duraspace.IsValue() { + vals = append(vals, "duraspace") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsDuracloudSetter) Overwrite(t *LocationsDuracloud) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Host.IsValue() { + t.Host = s.Host.MustGet() + } + if s.User.IsValue() { + t.User = s.User.MustGet() + } + if s.Password.IsValue() { + t.Password = s.Password.MustGet() + } + if s.Duraspace.IsValue() { + t.Duraspace = s.Duraspace.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsDuracloudSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDuraclouds.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Host.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Host.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.User.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.User.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Password.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Password.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Duraspace.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Duraspace.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsDuracloudSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_duracloud")...) +} + +func (s LocationsDuracloudSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 6) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Host.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "host")...), + mysql.Arg(s.Host), + }}) + } + + if s.User.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "user")...), + mysql.Arg(s.User), + }}) + } + + if s.Password.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "password")...), + mysql.Arg(s.Password), + }}) + } + + if s.Duraspace.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "duraspace")...), + mysql.Arg(s.Duraspace), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsDuracloud retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsDuracloud(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsDuracloud, error) { + if len(cols) == 0 { + return LocationsDuraclouds.Query( + sm.Where(LocationsDuraclouds.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsDuraclouds.Query( + sm.Where(LocationsDuraclouds.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsDuraclouds.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsDuracloudExists checks the presence of a single record by primary key +func LocationsDuracloudExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsDuraclouds.Query( + sm.Where(LocationsDuraclouds.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsDuracloud is retrieved from the database +func (o *LocationsDuracloud) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsDuraclouds.AfterSelectHooks.RunHooks(ctx, exec, LocationsDuracloudSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsDuraclouds.AfterInsertHooks.RunHooks(ctx, exec, LocationsDuracloudSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsDuraclouds.AfterUpdateHooks.RunHooks(ctx, exec, LocationsDuracloudSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsDuraclouds.AfterDeleteHooks.RunHooks(ctx, exec, LocationsDuracloudSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsDuracloud +func (o *LocationsDuracloud) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsDuracloud) pkEQ() dialect.Expression { + return mysql.Quote("locations_duracloud", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsDuracloud +func (o *LocationsDuracloud) Update(ctx context.Context, exec bob.Executor, s *LocationsDuracloudSetter) error { + _, err := LocationsDuraclouds.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsDuracloud record with an executor +func (o *LocationsDuracloud) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsDuraclouds.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsDuracloud using the executor +func (o *LocationsDuracloud) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsDuraclouds.Query( + sm.Where(LocationsDuraclouds.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsDuracloudSlice is retrieved from the database +func (o LocationsDuracloudSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsDuraclouds.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsDuraclouds.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsDuraclouds.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsDuraclouds.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsDuracloudSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_duracloud", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsDuracloudSlice) copyMatchingRows(from ...*LocationsDuracloud) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsDuracloudSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDuraclouds.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsDuracloud: + o.copyMatchingRows(retrieved) + case []*LocationsDuracloud: + o.copyMatchingRows(retrieved...) + case LocationsDuracloudSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsDuracloud or a slice of LocationsDuracloud + // then run the AfterUpdateHooks on the slice + _, err = LocationsDuraclouds.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsDuracloudSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsDuraclouds.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsDuracloud: + o.copyMatchingRows(retrieved) + case []*LocationsDuracloud: + o.copyMatchingRows(retrieved...) + case LocationsDuracloudSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsDuracloud or a slice of LocationsDuracloud + // then run the AfterDeleteHooks on the slice + _, err = LocationsDuraclouds.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsDuracloudSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsDuracloudSetter) error { + _, err := LocationsDuraclouds.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsDuracloudSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsDuraclouds.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsDuracloudSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsDuraclouds.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsDuracloud) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsDuracloudSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsDuracloudSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsDuracloud0 *LocationsDuracloud, locationsSpace1 *LocationsSpace) (*LocationsDuracloud, error) { + setter := &LocationsDuracloudSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsDuracloud0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsDuracloudSpaceLocationsSpace0: %w", err) + } + + return locationsDuracloud0, nil +} + +func (locationsDuracloud0 *LocationsDuracloud) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsDuracloudSpaceLocationsSpace0(ctx, exec, 1, locationsDuracloud0, locationsSpace1) + if err != nil { + return err + } + + locationsDuracloud0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsDuracloud = locationsDuracloud0 + + return nil +} + +func (locationsDuracloud0 *LocationsDuracloud) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsDuracloudSpaceLocationsSpace0(ctx, exec, 1, locationsDuracloud0, locationsSpace1) + if err != nil { + return err + } + + locationsDuracloud0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsDuracloud = locationsDuracloud0 + + return nil +} + +type locationsDuracloudWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Host mysql.WhereMod[Q, string] + User mysql.WhereMod[Q, string] + Password mysql.WhereMod[Q, string] + Duraspace mysql.WhereMod[Q, string] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsDuracloudWhere[Q]) AliasedAs(alias string) locationsDuracloudWhere[Q] { + return buildLocationsDuracloudWhere[Q](buildLocationsDuracloudColumns(alias)) +} + +func buildLocationsDuracloudWhere[Q mysql.Filterable](cols locationsDuracloudColumns) locationsDuracloudWhere[Q] { + return locationsDuracloudWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Host: mysql.Where[Q, string](cols.Host), + User: mysql.Where[Q, string](cols.User), + Password: mysql.Where[Q, string](cols.Password), + Duraspace: mysql.Where[Q, string](cols.Duraspace), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsDuracloud) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsDuracloud cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsDuracloud = o + } + return nil + default: + return fmt.Errorf("locationsDuracloud has no relationship %q", name) + } +} + +type locationsDuracloudPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsDuracloudPreloader() locationsDuracloudPreloader { + return locationsDuracloudPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsDuraclouds, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsDuracloudThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsDuracloudThenLoader[Q orm.Loadable]() locationsDuracloudThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsDuracloudThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsDuracloud's SpaceLocationsSpace into the .R struct +func (o *LocationsDuracloud) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsDuracloud = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsDuracloud's SpaceLocationsSpace into the .R struct +func (os LocationsDuracloudSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsDuracloud = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsDuracloudJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsDuracloudJoins[Q]) aliasedAs(alias string) locationsDuracloudJoins[Q] { + return buildLocationsDuracloudJoins[Q](buildLocationsDuracloudColumns(alias), j.typ) +} + +func buildLocationsDuracloudJoins[Q dialect.Joinable](cols locationsDuracloudColumns, typ string) locationsDuracloudJoins[Q] { + return locationsDuracloudJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_event.bob.go b/database/storage_service/models/locations_event.bob.go new file mode 100644 index 0000000..7b2c96a --- /dev/null +++ b/database/storage_service/models/locations_event.bob.go @@ -0,0 +1,1180 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsEvent is an object representing the database table. +type LocationsEvent struct { + ID int32 `db:"id,pk,autoincr" ` + EventType string `db:"event_type" ` + EventReason string `db:"event_reason" ` + UserID uint32 `db:"user_id" ` + UserEmail string `db:"user_email" ` + Status string `db:"status" ` + StatusReason null.Val[string] `db:"status_reason" ` + StatusTime time.Time `db:"status_time" ` + StoreData null.Val[string] `db:"store_data" ` + AdminIDID null.Val[int32] `db:"admin_id_id" ` + PackageID string `db:"package_id" ` + PipelineID string `db:"pipeline_id" ` + + R locationsEventR `db:"-" ` +} + +// LocationsEventSlice is an alias for a slice of pointers to LocationsEvent. +// This should almost always be used instead of []*LocationsEvent. +type LocationsEventSlice []*LocationsEvent + +// LocationsEvents contains methods to work with the locations_event table +var LocationsEvents = mysql.NewTablex[*LocationsEvent, LocationsEventSlice, *LocationsEventSetter]("locations_event", buildLocationsEventColumns("locations_event"), []string{"id"}) + +// LocationsEventsQuery is a query on the locations_event table +type LocationsEventsQuery = *mysql.ViewQuery[*LocationsEvent, LocationsEventSlice] + +// locationsEventR is where relationships are stored. +type locationsEventR struct { + AdminIDAuthUser *AuthUser // locations_event_admin_id_id_4a50d36a_fk_auth_user_id + PackageLocationsPackage *LocationsPackage // locations_event_package_id_50db610f_fk_locations_package_uuid + PipelineLocationsPipeline *LocationsPipeline // locations_event_pipeline_id_5188361f_fk_locations_pipeline_uuid +} + +func buildLocationsEventColumns(alias string) locationsEventColumns { + return locationsEventColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "event_type", "event_reason", "user_id", "user_email", "status", "status_reason", "status_time", "store_data", "admin_id_id", "package_id", "pipeline_id", + ).WithParent("locations_event"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + EventType: mysql.Quote(alias, "event_type"), + EventReason: mysql.Quote(alias, "event_reason"), + UserID: mysql.Quote(alias, "user_id"), + UserEmail: mysql.Quote(alias, "user_email"), + Status: mysql.Quote(alias, "status"), + StatusReason: mysql.Quote(alias, "status_reason"), + StatusTime: mysql.Quote(alias, "status_time"), + StoreData: mysql.Quote(alias, "store_data"), + AdminIDID: mysql.Quote(alias, "admin_id_id"), + PackageID: mysql.Quote(alias, "package_id"), + PipelineID: mysql.Quote(alias, "pipeline_id"), + } +} + +type locationsEventColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + EventType mysql.Expression + EventReason mysql.Expression + UserID mysql.Expression + UserEmail mysql.Expression + Status mysql.Expression + StatusReason mysql.Expression + StatusTime mysql.Expression + StoreData mysql.Expression + AdminIDID mysql.Expression + PackageID mysql.Expression + PipelineID mysql.Expression +} + +func (c locationsEventColumns) Alias() string { + return c.tableAlias +} + +func (locationsEventColumns) AliasedAs(alias string) locationsEventColumns { + return buildLocationsEventColumns(alias) +} + +// LocationsEventSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsEventSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + EventType omit.Val[string] `db:"event_type" ` + EventReason omit.Val[string] `db:"event_reason" ` + UserID omit.Val[uint32] `db:"user_id" ` + UserEmail omit.Val[string] `db:"user_email" ` + Status omit.Val[string] `db:"status" ` + StatusReason omitnull.Val[string] `db:"status_reason" ` + StatusTime omit.Val[time.Time] `db:"status_time" ` + StoreData omitnull.Val[string] `db:"store_data" ` + AdminIDID omitnull.Val[int32] `db:"admin_id_id" ` + PackageID omit.Val[string] `db:"package_id" ` + PipelineID omit.Val[string] `db:"pipeline_id" ` +} + +func (s LocationsEventSetter) SetColumns() []string { + vals := make([]string, 0, 12) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.EventType.IsValue() { + vals = append(vals, "event_type") + } + if s.EventReason.IsValue() { + vals = append(vals, "event_reason") + } + if s.UserID.IsValue() { + vals = append(vals, "user_id") + } + if s.UserEmail.IsValue() { + vals = append(vals, "user_email") + } + if s.Status.IsValue() { + vals = append(vals, "status") + } + if !s.StatusReason.IsUnset() { + vals = append(vals, "status_reason") + } + if s.StatusTime.IsValue() { + vals = append(vals, "status_time") + } + if !s.StoreData.IsUnset() { + vals = append(vals, "store_data") + } + if !s.AdminIDID.IsUnset() { + vals = append(vals, "admin_id_id") + } + if s.PackageID.IsValue() { + vals = append(vals, "package_id") + } + if s.PipelineID.IsValue() { + vals = append(vals, "pipeline_id") + } + return vals +} + +func (s LocationsEventSetter) Overwrite(t *LocationsEvent) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.EventType.IsValue() { + t.EventType = s.EventType.MustGet() + } + if s.EventReason.IsValue() { + t.EventReason = s.EventReason.MustGet() + } + if s.UserID.IsValue() { + t.UserID = s.UserID.MustGet() + } + if s.UserEmail.IsValue() { + t.UserEmail = s.UserEmail.MustGet() + } + if s.Status.IsValue() { + t.Status = s.Status.MustGet() + } + if !s.StatusReason.IsUnset() { + t.StatusReason = s.StatusReason.MustGetNull() + } + if s.StatusTime.IsValue() { + t.StatusTime = s.StatusTime.MustGet() + } + if !s.StoreData.IsUnset() { + t.StoreData = s.StoreData.MustGetNull() + } + if !s.AdminIDID.IsUnset() { + t.AdminIDID = s.AdminIDID.MustGetNull() + } + if s.PackageID.IsValue() { + t.PackageID = s.PackageID.MustGet() + } + if s.PipelineID.IsValue() { + t.PipelineID = s.PipelineID.MustGet() + } +} + +func (s *LocationsEventSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsEvents.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.EventType.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.EventType.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.EventReason.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.EventReason.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UserID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UserID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UserEmail.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UserEmail.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Status.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Status.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.StatusReason.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.StatusReason.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.StatusTime.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.StatusTime.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.StoreData.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.StoreData.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.AdminIDID.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AdminIDID.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.PackageID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PackageID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.PipelineID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PipelineID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsEventSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_event")...) +} + +func (s LocationsEventSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 12) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.EventType.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "event_type")...), + mysql.Arg(s.EventType), + }}) + } + + if s.EventReason.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "event_reason")...), + mysql.Arg(s.EventReason), + }}) + } + + if s.UserID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "user_id")...), + mysql.Arg(s.UserID), + }}) + } + + if s.UserEmail.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "user_email")...), + mysql.Arg(s.UserEmail), + }}) + } + + if s.Status.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "status")...), + mysql.Arg(s.Status), + }}) + } + + if !s.StatusReason.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "status_reason")...), + mysql.Arg(s.StatusReason), + }}) + } + + if s.StatusTime.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "status_time")...), + mysql.Arg(s.StatusTime), + }}) + } + + if !s.StoreData.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "store_data")...), + mysql.Arg(s.StoreData), + }}) + } + + if !s.AdminIDID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "admin_id_id")...), + mysql.Arg(s.AdminIDID), + }}) + } + + if s.PackageID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "package_id")...), + mysql.Arg(s.PackageID), + }}) + } + + if s.PipelineID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "pipeline_id")...), + mysql.Arg(s.PipelineID), + }}) + } + + return exprs +} + +// FindLocationsEvent retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsEvent(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsEvent, error) { + if len(cols) == 0 { + return LocationsEvents.Query( + sm.Where(LocationsEvents.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsEvents.Query( + sm.Where(LocationsEvents.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsEvents.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsEventExists checks the presence of a single record by primary key +func LocationsEventExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsEvents.Query( + sm.Where(LocationsEvents.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsEvent is retrieved from the database +func (o *LocationsEvent) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsEvents.AfterSelectHooks.RunHooks(ctx, exec, LocationsEventSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsEvents.AfterInsertHooks.RunHooks(ctx, exec, LocationsEventSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsEvents.AfterUpdateHooks.RunHooks(ctx, exec, LocationsEventSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsEvents.AfterDeleteHooks.RunHooks(ctx, exec, LocationsEventSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsEvent +func (o *LocationsEvent) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsEvent) pkEQ() dialect.Expression { + return mysql.Quote("locations_event", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsEvent +func (o *LocationsEvent) Update(ctx context.Context, exec bob.Executor, s *LocationsEventSetter) error { + _, err := LocationsEvents.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsEvent record with an executor +func (o *LocationsEvent) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsEvents.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsEvent using the executor +func (o *LocationsEvent) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsEvents.Query( + sm.Where(LocationsEvents.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsEventSlice is retrieved from the database +func (o LocationsEventSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsEvents.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsEvents.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsEvents.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsEvents.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsEventSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_event", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsEventSlice) copyMatchingRows(from ...*LocationsEvent) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsEventSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsEvents.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsEvent: + o.copyMatchingRows(retrieved) + case []*LocationsEvent: + o.copyMatchingRows(retrieved...) + case LocationsEventSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsEvent or a slice of LocationsEvent + // then run the AfterUpdateHooks on the slice + _, err = LocationsEvents.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsEventSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsEvents.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsEvent: + o.copyMatchingRows(retrieved) + case []*LocationsEvent: + o.copyMatchingRows(retrieved...) + case LocationsEventSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsEvent or a slice of LocationsEvent + // then run the AfterDeleteHooks on the slice + _, err = LocationsEvents.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsEventSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsEventSetter) error { + _, err := LocationsEvents.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsEventSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsEvents.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsEventSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsEvents.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// AdminIDAuthUser starts a query for related objects on auth_user +func (o *LocationsEvent) AdminIDAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + return AuthUsers.Query(append(mods, + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(o.AdminIDID))), + )...) +} + +func (os LocationsEventSlice) AdminIDAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.AdminIDID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUsers.Query(append(mods, + sm.Where(mysql.Group(AuthUsers.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// PackageLocationsPackage starts a query for related objects on locations_package +func (o *LocationsEvent) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.UUID.EQ(mysql.Arg(o.PackageID))), + )...) +} + +func (os LocationsEventSlice) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PackageID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +// PipelineLocationsPipeline starts a query for related objects on locations_pipeline +func (o *LocationsEvent) PipelineLocationsPipeline(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPipelinesQuery { + return LocationsPipelines.Query(append(mods, + sm.Where(LocationsPipelines.Columns.UUID.EQ(mysql.Arg(o.PipelineID))), + )...) +} + +func (os LocationsEventSlice) PipelineLocationsPipeline(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPipelinesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PipelineID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPipelines.Query(append(mods, + sm.Where(mysql.Group(LocationsPipelines.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsEventAdminIDAuthUser0(ctx context.Context, exec bob.Executor, count int, locationsEvent0 *LocationsEvent, authUser1 *AuthUser) (*LocationsEvent, error) { + setter := &LocationsEventSetter{ + AdminIDID: omitnull.From(authUser1.ID), + } + + err := locationsEvent0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsEventAdminIDAuthUser0: %w", err) + } + + return locationsEvent0, nil +} + +func (locationsEvent0 *LocationsEvent) InsertAdminIDAuthUser(ctx context.Context, exec bob.Executor, related *AuthUserSetter) error { + var err error + + authUser1, err := AuthUsers.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsEventAdminIDAuthUser0(ctx, exec, 1, locationsEvent0, authUser1) + if err != nil { + return err + } + + locationsEvent0.R.AdminIDAuthUser = authUser1 + + authUser1.R.AdminIDLocationsEvents = append(authUser1.R.AdminIDLocationsEvents, locationsEvent0) + + return nil +} + +func (locationsEvent0 *LocationsEvent) AttachAdminIDAuthUser(ctx context.Context, exec bob.Executor, authUser1 *AuthUser) error { + var err error + + _, err = attachLocationsEventAdminIDAuthUser0(ctx, exec, 1, locationsEvent0, authUser1) + if err != nil { + return err + } + + locationsEvent0.R.AdminIDAuthUser = authUser1 + + authUser1.R.AdminIDLocationsEvents = append(authUser1.R.AdminIDLocationsEvents, locationsEvent0) + + return nil +} + +func attachLocationsEventPackageLocationsPackage0(ctx context.Context, exec bob.Executor, count int, locationsEvent0 *LocationsEvent, locationsPackage1 *LocationsPackage) (*LocationsEvent, error) { + setter := &LocationsEventSetter{ + PackageID: omit.From(locationsPackage1.UUID), + } + + err := locationsEvent0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsEventPackageLocationsPackage0: %w", err) + } + + return locationsEvent0, nil +} + +func (locationsEvent0 *LocationsEvent) InsertPackageLocationsPackage(ctx context.Context, exec bob.Executor, related *LocationsPackageSetter) error { + var err error + + locationsPackage1, err := LocationsPackages.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsEventPackageLocationsPackage0(ctx, exec, 1, locationsEvent0, locationsPackage1) + if err != nil { + return err + } + + locationsEvent0.R.PackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.PackageLocationsEvents = append(locationsPackage1.R.PackageLocationsEvents, locationsEvent0) + + return nil +} + +func (locationsEvent0 *LocationsEvent) AttachPackageLocationsPackage(ctx context.Context, exec bob.Executor, locationsPackage1 *LocationsPackage) error { + var err error + + _, err = attachLocationsEventPackageLocationsPackage0(ctx, exec, 1, locationsEvent0, locationsPackage1) + if err != nil { + return err + } + + locationsEvent0.R.PackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.PackageLocationsEvents = append(locationsPackage1.R.PackageLocationsEvents, locationsEvent0) + + return nil +} + +func attachLocationsEventPipelineLocationsPipeline0(ctx context.Context, exec bob.Executor, count int, locationsEvent0 *LocationsEvent, locationsPipeline1 *LocationsPipeline) (*LocationsEvent, error) { + setter := &LocationsEventSetter{ + PipelineID: omit.From(locationsPipeline1.UUID), + } + + err := locationsEvent0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsEventPipelineLocationsPipeline0: %w", err) + } + + return locationsEvent0, nil +} + +func (locationsEvent0 *LocationsEvent) InsertPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, related *LocationsPipelineSetter) error { + var err error + + locationsPipeline1, err := LocationsPipelines.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsEventPipelineLocationsPipeline0(ctx, exec, 1, locationsEvent0, locationsPipeline1) + if err != nil { + return err + } + + locationsEvent0.R.PipelineLocationsPipeline = locationsPipeline1 + + locationsPipeline1.R.PipelineLocationsEvents = append(locationsPipeline1.R.PipelineLocationsEvents, locationsEvent0) + + return nil +} + +func (locationsEvent0 *LocationsEvent) AttachPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, locationsPipeline1 *LocationsPipeline) error { + var err error + + _, err = attachLocationsEventPipelineLocationsPipeline0(ctx, exec, 1, locationsEvent0, locationsPipeline1) + if err != nil { + return err + } + + locationsEvent0.R.PipelineLocationsPipeline = locationsPipeline1 + + locationsPipeline1.R.PipelineLocationsEvents = append(locationsPipeline1.R.PipelineLocationsEvents, locationsEvent0) + + return nil +} + +type locationsEventWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + EventType mysql.WhereMod[Q, string] + EventReason mysql.WhereMod[Q, string] + UserID mysql.WhereMod[Q, uint32] + UserEmail mysql.WhereMod[Q, string] + Status mysql.WhereMod[Q, string] + StatusReason mysql.WhereNullMod[Q, string] + StatusTime mysql.WhereMod[Q, time.Time] + StoreData mysql.WhereNullMod[Q, string] + AdminIDID mysql.WhereNullMod[Q, int32] + PackageID mysql.WhereMod[Q, string] + PipelineID mysql.WhereMod[Q, string] +} + +func (locationsEventWhere[Q]) AliasedAs(alias string) locationsEventWhere[Q] { + return buildLocationsEventWhere[Q](buildLocationsEventColumns(alias)) +} + +func buildLocationsEventWhere[Q mysql.Filterable](cols locationsEventColumns) locationsEventWhere[Q] { + return locationsEventWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + EventType: mysql.Where[Q, string](cols.EventType), + EventReason: mysql.Where[Q, string](cols.EventReason), + UserID: mysql.Where[Q, uint32](cols.UserID), + UserEmail: mysql.Where[Q, string](cols.UserEmail), + Status: mysql.Where[Q, string](cols.Status), + StatusReason: mysql.WhereNull[Q, string](cols.StatusReason), + StatusTime: mysql.Where[Q, time.Time](cols.StatusTime), + StoreData: mysql.WhereNull[Q, string](cols.StoreData), + AdminIDID: mysql.WhereNull[Q, int32](cols.AdminIDID), + PackageID: mysql.Where[Q, string](cols.PackageID), + PipelineID: mysql.Where[Q, string](cols.PipelineID), + } +} + +func (o *LocationsEvent) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "AdminIDAuthUser": + rel, ok := retrieved.(*AuthUser) + if !ok { + return fmt.Errorf("locationsEvent cannot load %T as %q", retrieved, name) + } + + o.R.AdminIDAuthUser = rel + + if rel != nil { + rel.R.AdminIDLocationsEvents = LocationsEventSlice{o} + } + return nil + case "PackageLocationsPackage": + rel, ok := retrieved.(*LocationsPackage) + if !ok { + return fmt.Errorf("locationsEvent cannot load %T as %q", retrieved, name) + } + + o.R.PackageLocationsPackage = rel + + if rel != nil { + rel.R.PackageLocationsEvents = LocationsEventSlice{o} + } + return nil + case "PipelineLocationsPipeline": + rel, ok := retrieved.(*LocationsPipeline) + if !ok { + return fmt.Errorf("locationsEvent cannot load %T as %q", retrieved, name) + } + + o.R.PipelineLocationsPipeline = rel + + if rel != nil { + rel.R.PipelineLocationsEvents = LocationsEventSlice{o} + } + return nil + default: + return fmt.Errorf("locationsEvent has no relationship %q", name) + } +} + +type locationsEventPreloader struct { + AdminIDAuthUser func(...mysql.PreloadOption) mysql.Preloader + PackageLocationsPackage func(...mysql.PreloadOption) mysql.Preloader + PipelineLocationsPipeline func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsEventPreloader() locationsEventPreloader { + return locationsEventPreloader{ + AdminIDAuthUser: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthUser, AuthUserSlice](mysql.PreloadRel{ + Name: "AdminIDAuthUser", + Sides: []mysql.PreloadSide{ + { + From: LocationsEvents, + To: AuthUsers, + FromColumns: []string{"admin_id_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthUsers.Columns.Names(), opts...) + }, + PackageLocationsPackage: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPackage, LocationsPackageSlice](mysql.PreloadRel{ + Name: "PackageLocationsPackage", + Sides: []mysql.PreloadSide{ + { + From: LocationsEvents, + To: LocationsPackages, + FromColumns: []string{"package_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsPackages.Columns.Names(), opts...) + }, + PipelineLocationsPipeline: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPipeline, LocationsPipelineSlice](mysql.PreloadRel{ + Name: "PipelineLocationsPipeline", + Sides: []mysql.PreloadSide{ + { + From: LocationsEvents, + To: LocationsPipelines, + FromColumns: []string{"pipeline_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsPipelines.Columns.Names(), opts...) + }, + } +} + +type locationsEventThenLoader[Q orm.Loadable] struct { + AdminIDAuthUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PackageLocationsPackage func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PipelineLocationsPipeline func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsEventThenLoader[Q orm.Loadable]() locationsEventThenLoader[Q] { + type AdminIDAuthUserLoadInterface interface { + LoadAdminIDAuthUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PackageLocationsPackageLoadInterface interface { + LoadPackageLocationsPackage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PipelineLocationsPipelineLoadInterface interface { + LoadPipelineLocationsPipeline(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsEventThenLoader[Q]{ + AdminIDAuthUser: thenLoadBuilder[Q]( + "AdminIDAuthUser", + func(ctx context.Context, exec bob.Executor, retrieved AdminIDAuthUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadAdminIDAuthUser(ctx, exec, mods...) + }, + ), + PackageLocationsPackage: thenLoadBuilder[Q]( + "PackageLocationsPackage", + func(ctx context.Context, exec bob.Executor, retrieved PackageLocationsPackageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPackageLocationsPackage(ctx, exec, mods...) + }, + ), + PipelineLocationsPipeline: thenLoadBuilder[Q]( + "PipelineLocationsPipeline", + func(ctx context.Context, exec bob.Executor, retrieved PipelineLocationsPipelineLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPipelineLocationsPipeline(ctx, exec, mods...) + }, + ), + } +} + +// LoadAdminIDAuthUser loads the locationsEvent's AdminIDAuthUser into the .R struct +func (o *LocationsEvent) LoadAdminIDAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.AdminIDAuthUser = nil + + related, err := o.AdminIDAuthUser(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.AdminIDLocationsEvents = LocationsEventSlice{o} + + o.R.AdminIDAuthUser = related + return nil +} + +// LoadAdminIDAuthUser loads the locationsEvent's AdminIDAuthUser into the .R struct +func (os LocationsEventSlice) LoadAdminIDAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUsers, err := os.AdminIDAuthUser(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUsers { + if !o.AdminIDID.IsValue() { + continue + } + + if !(o.AdminIDID.IsValue() && o.AdminIDID.MustGet() == rel.ID) { + continue + } + + rel.R.AdminIDLocationsEvents = append(rel.R.AdminIDLocationsEvents, o) + + o.R.AdminIDAuthUser = rel + break + } + } + + return nil +} + +// LoadPackageLocationsPackage loads the locationsEvent's PackageLocationsPackage into the .R struct +func (o *LocationsEvent) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PackageLocationsPackage = nil + + related, err := o.PackageLocationsPackage(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PackageLocationsEvents = LocationsEventSlice{o} + + o.R.PackageLocationsPackage = related + return nil +} + +// LoadPackageLocationsPackage loads the locationsEvent's PackageLocationsPackage into the .R struct +func (os LocationsEventSlice) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.PackageLocationsPackage(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !(o.PackageID == rel.UUID) { + continue + } + + rel.R.PackageLocationsEvents = append(rel.R.PackageLocationsEvents, o) + + o.R.PackageLocationsPackage = rel + break + } + } + + return nil +} + +// LoadPipelineLocationsPipeline loads the locationsEvent's PipelineLocationsPipeline into the .R struct +func (o *LocationsEvent) LoadPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PipelineLocationsPipeline = nil + + related, err := o.PipelineLocationsPipeline(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PipelineLocationsEvents = LocationsEventSlice{o} + + o.R.PipelineLocationsPipeline = related + return nil +} + +// LoadPipelineLocationsPipeline loads the locationsEvent's PipelineLocationsPipeline into the .R struct +func (os LocationsEventSlice) LoadPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPipelines, err := os.PipelineLocationsPipeline(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPipelines { + + if !(o.PipelineID == rel.UUID) { + continue + } + + rel.R.PipelineLocationsEvents = append(rel.R.PipelineLocationsEvents, o) + + o.R.PipelineLocationsPipeline = rel + break + } + } + + return nil +} + +type locationsEventJoins[Q dialect.Joinable] struct { + typ string + AdminIDAuthUser modAs[Q, authUserColumns] + PackageLocationsPackage modAs[Q, locationsPackageColumns] + PipelineLocationsPipeline modAs[Q, locationsPipelineColumns] +} + +func (j locationsEventJoins[Q]) aliasedAs(alias string) locationsEventJoins[Q] { + return buildLocationsEventJoins[Q](buildLocationsEventColumns(alias), j.typ) +} + +func buildLocationsEventJoins[Q dialect.Joinable](cols locationsEventColumns, typ string) locationsEventJoins[Q] { + return locationsEventJoins[Q]{ + typ: typ, + AdminIDAuthUser: modAs[Q, authUserColumns]{ + c: AuthUsers.Columns, + f: func(to authUserColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUsers.Name().As(to.Alias())).On( + to.ID.EQ(cols.AdminIDID), + )) + } + + return mods + }, + }, + PackageLocationsPackage: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.UUID.EQ(cols.PackageID), + )) + } + + return mods + }, + }, + PipelineLocationsPipeline: modAs[Q, locationsPipelineColumns]{ + c: LocationsPipelines.Columns, + f: func(to locationsPipelineColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPipelines.Name().As(to.Alias())).On( + to.UUID.EQ(cols.PipelineID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_fedora.bob.go b/database/storage_service/models/locations_fedora.bob.go new file mode 100644 index 0000000..326cdca --- /dev/null +++ b/database/storage_service/models/locations_fedora.bob.go @@ -0,0 +1,664 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsFedora is an object representing the database table. +type LocationsFedora struct { + ID int32 `db:"id,pk,autoincr" ` + FedoraUser string `db:"fedora_user" ` + FedoraPassword string `db:"fedora_password" ` + FedoraName string `db:"fedora_name" ` + SpaceID string `db:"space_id" ` + + R locationsFedoraR `db:"-" ` +} + +// LocationsFedoraSlice is an alias for a slice of pointers to LocationsFedora. +// This should almost always be used instead of []*LocationsFedora. +type LocationsFedoraSlice []*LocationsFedora + +// LocationsFedoras contains methods to work with the locations_fedora table +var LocationsFedoras = mysql.NewTablex[*LocationsFedora, LocationsFedoraSlice, *LocationsFedoraSetter]("locations_fedora", buildLocationsFedoraColumns("locations_fedora"), []string{"id"}, []string{"space_id"}) + +// LocationsFedorasQuery is a query on the locations_fedora table +type LocationsFedorasQuery = *mysql.ViewQuery[*LocationsFedora, LocationsFedoraSlice] + +// locationsFedoraR is where relationships are stored. +type locationsFedoraR struct { + SpaceLocationsSpace *LocationsSpace // locations_fedora_space_id_088fe895_fk_locations_space_uuid +} + +func buildLocationsFedoraColumns(alias string) locationsFedoraColumns { + return locationsFedoraColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "fedora_user", "fedora_password", "fedora_name", "space_id", + ).WithParent("locations_fedora"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + FedoraUser: mysql.Quote(alias, "fedora_user"), + FedoraPassword: mysql.Quote(alias, "fedora_password"), + FedoraName: mysql.Quote(alias, "fedora_name"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsFedoraColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + FedoraUser mysql.Expression + FedoraPassword mysql.Expression + FedoraName mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsFedoraColumns) Alias() string { + return c.tableAlias +} + +func (locationsFedoraColumns) AliasedAs(alias string) locationsFedoraColumns { + return buildLocationsFedoraColumns(alias) +} + +// LocationsFedoraSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsFedoraSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + FedoraUser omit.Val[string] `db:"fedora_user" ` + FedoraPassword omit.Val[string] `db:"fedora_password" ` + FedoraName omit.Val[string] `db:"fedora_name" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsFedoraSetter) SetColumns() []string { + vals := make([]string, 0, 5) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.FedoraUser.IsValue() { + vals = append(vals, "fedora_user") + } + if s.FedoraPassword.IsValue() { + vals = append(vals, "fedora_password") + } + if s.FedoraName.IsValue() { + vals = append(vals, "fedora_name") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsFedoraSetter) Overwrite(t *LocationsFedora) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.FedoraUser.IsValue() { + t.FedoraUser = s.FedoraUser.MustGet() + } + if s.FedoraPassword.IsValue() { + t.FedoraPassword = s.FedoraPassword.MustGet() + } + if s.FedoraName.IsValue() { + t.FedoraName = s.FedoraName.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsFedoraSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFedoras.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.FedoraUser.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.FedoraUser.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.FedoraPassword.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.FedoraPassword.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.FedoraName.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.FedoraName.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsFedoraSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_fedora")...) +} + +func (s LocationsFedoraSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 5) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.FedoraUser.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "fedora_user")...), + mysql.Arg(s.FedoraUser), + }}) + } + + if s.FedoraPassword.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "fedora_password")...), + mysql.Arg(s.FedoraPassword), + }}) + } + + if s.FedoraName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "fedora_name")...), + mysql.Arg(s.FedoraName), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsFedora retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsFedora(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsFedora, error) { + if len(cols) == 0 { + return LocationsFedoras.Query( + sm.Where(LocationsFedoras.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsFedoras.Query( + sm.Where(LocationsFedoras.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsFedoras.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsFedoraExists checks the presence of a single record by primary key +func LocationsFedoraExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsFedoras.Query( + sm.Where(LocationsFedoras.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsFedora is retrieved from the database +func (o *LocationsFedora) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsFedoras.AfterSelectHooks.RunHooks(ctx, exec, LocationsFedoraSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsFedoras.AfterInsertHooks.RunHooks(ctx, exec, LocationsFedoraSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsFedoras.AfterUpdateHooks.RunHooks(ctx, exec, LocationsFedoraSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsFedoras.AfterDeleteHooks.RunHooks(ctx, exec, LocationsFedoraSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsFedora +func (o *LocationsFedora) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsFedora) pkEQ() dialect.Expression { + return mysql.Quote("locations_fedora", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsFedora +func (o *LocationsFedora) Update(ctx context.Context, exec bob.Executor, s *LocationsFedoraSetter) error { + _, err := LocationsFedoras.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsFedora record with an executor +func (o *LocationsFedora) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsFedoras.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsFedora using the executor +func (o *LocationsFedora) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsFedoras.Query( + sm.Where(LocationsFedoras.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsFedoraSlice is retrieved from the database +func (o LocationsFedoraSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsFedoras.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsFedoras.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsFedoras.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsFedoras.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsFedoraSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_fedora", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsFedoraSlice) copyMatchingRows(from ...*LocationsFedora) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsFedoraSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFedoras.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsFedora: + o.copyMatchingRows(retrieved) + case []*LocationsFedora: + o.copyMatchingRows(retrieved...) + case LocationsFedoraSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsFedora or a slice of LocationsFedora + // then run the AfterUpdateHooks on the slice + _, err = LocationsFedoras.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsFedoraSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFedoras.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsFedora: + o.copyMatchingRows(retrieved) + case []*LocationsFedora: + o.copyMatchingRows(retrieved...) + case LocationsFedoraSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsFedora or a slice of LocationsFedora + // then run the AfterDeleteHooks on the slice + _, err = LocationsFedoras.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsFedoraSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsFedoraSetter) error { + _, err := LocationsFedoras.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsFedoraSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsFedoras.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsFedoraSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsFedoras.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsFedora) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsFedoraSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsFedoraSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsFedora0 *LocationsFedora, locationsSpace1 *LocationsSpace) (*LocationsFedora, error) { + setter := &LocationsFedoraSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsFedora0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsFedoraSpaceLocationsSpace0: %w", err) + } + + return locationsFedora0, nil +} + +func (locationsFedora0 *LocationsFedora) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsFedoraSpaceLocationsSpace0(ctx, exec, 1, locationsFedora0, locationsSpace1) + if err != nil { + return err + } + + locationsFedora0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsFedora = locationsFedora0 + + return nil +} + +func (locationsFedora0 *LocationsFedora) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsFedoraSpaceLocationsSpace0(ctx, exec, 1, locationsFedora0, locationsSpace1) + if err != nil { + return err + } + + locationsFedora0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsFedora = locationsFedora0 + + return nil +} + +type locationsFedoraWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + FedoraUser mysql.WhereMod[Q, string] + FedoraPassword mysql.WhereMod[Q, string] + FedoraName mysql.WhereMod[Q, string] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsFedoraWhere[Q]) AliasedAs(alias string) locationsFedoraWhere[Q] { + return buildLocationsFedoraWhere[Q](buildLocationsFedoraColumns(alias)) +} + +func buildLocationsFedoraWhere[Q mysql.Filterable](cols locationsFedoraColumns) locationsFedoraWhere[Q] { + return locationsFedoraWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + FedoraUser: mysql.Where[Q, string](cols.FedoraUser), + FedoraPassword: mysql.Where[Q, string](cols.FedoraPassword), + FedoraName: mysql.Where[Q, string](cols.FedoraName), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsFedora) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsFedora cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsFedora = o + } + return nil + default: + return fmt.Errorf("locationsFedora has no relationship %q", name) + } +} + +type locationsFedoraPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsFedoraPreloader() locationsFedoraPreloader { + return locationsFedoraPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsFedoras, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsFedoraThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsFedoraThenLoader[Q orm.Loadable]() locationsFedoraThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsFedoraThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsFedora's SpaceLocationsSpace into the .R struct +func (o *LocationsFedora) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsFedora = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsFedora's SpaceLocationsSpace into the .R struct +func (os LocationsFedoraSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsFedora = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsFedoraJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsFedoraJoins[Q]) aliasedAs(alias string) locationsFedoraJoins[Q] { + return buildLocationsFedoraJoins[Q](buildLocationsFedoraColumns(alias), j.typ) +} + +func buildLocationsFedoraJoins[Q dialect.Joinable](cols locationsFedoraColumns, typ string) locationsFedoraJoins[Q] { + return locationsFedoraJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_file.bob.go b/database/storage_service/models/locations_file.bob.go new file mode 100644 index 0000000..a77291a --- /dev/null +++ b/database/storage_service/models/locations_file.bob.go @@ -0,0 +1,789 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsFile is an object representing the database table. +type LocationsFile struct { + ID int32 `db:"id,pk,autoincr" ` + UUID string `db:"uuid" ` + Name string `db:"name" ` + SourceID string `db:"source_id" ` + Checksum string `db:"checksum" ` + Stored bool `db:"stored" ` + Accessionid string `db:"accessionid" ` + Origin string `db:"origin" ` + PackageID null.Val[int32] `db:"package_id" ` + SourcePackage string `db:"source_package" ` + + R locationsFileR `db:"-" ` +} + +// LocationsFileSlice is an alias for a slice of pointers to LocationsFile. +// This should almost always be used instead of []*LocationsFile. +type LocationsFileSlice []*LocationsFile + +// LocationsFiles contains methods to work with the locations_file table +var LocationsFiles = mysql.NewTablex[*LocationsFile, LocationsFileSlice, *LocationsFileSetter]("locations_file", buildLocationsFileColumns("locations_file"), []string{"id"}, []string{"uuid"}) + +// LocationsFilesQuery is a query on the locations_file table +type LocationsFilesQuery = *mysql.ViewQuery[*LocationsFile, LocationsFileSlice] + +// locationsFileR is where relationships are stored. +type locationsFileR struct { + PackageLocationsPackage *LocationsPackage // locations_file_package_id_dd478d69_fk_locations_package_id +} + +func buildLocationsFileColumns(alias string) locationsFileColumns { + return locationsFileColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "uuid", "name", "source_id", "checksum", "stored", "accessionid", "origin", "package_id", "source_package", + ).WithParent("locations_file"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UUID: mysql.Quote(alias, "uuid"), + Name: mysql.Quote(alias, "name"), + SourceID: mysql.Quote(alias, "source_id"), + Checksum: mysql.Quote(alias, "checksum"), + Stored: mysql.Quote(alias, "stored"), + Accessionid: mysql.Quote(alias, "accessionid"), + Origin: mysql.Quote(alias, "origin"), + PackageID: mysql.Quote(alias, "package_id"), + SourcePackage: mysql.Quote(alias, "source_package"), + } +} + +type locationsFileColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UUID mysql.Expression + Name mysql.Expression + SourceID mysql.Expression + Checksum mysql.Expression + Stored mysql.Expression + Accessionid mysql.Expression + Origin mysql.Expression + PackageID mysql.Expression + SourcePackage mysql.Expression +} + +func (c locationsFileColumns) Alias() string { + return c.tableAlias +} + +func (locationsFileColumns) AliasedAs(alias string) locationsFileColumns { + return buildLocationsFileColumns(alias) +} + +// LocationsFileSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsFileSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UUID omit.Val[string] `db:"uuid" ` + Name omit.Val[string] `db:"name" ` + SourceID omit.Val[string] `db:"source_id" ` + Checksum omit.Val[string] `db:"checksum" ` + Stored omit.Val[bool] `db:"stored" ` + Accessionid omit.Val[string] `db:"accessionid" ` + Origin omit.Val[string] `db:"origin" ` + PackageID omitnull.Val[int32] `db:"package_id" ` + SourcePackage omit.Val[string] `db:"source_package" ` +} + +func (s LocationsFileSetter) SetColumns() []string { + vals := make([]string, 0, 10) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UUID.IsValue() { + vals = append(vals, "uuid") + } + if s.Name.IsValue() { + vals = append(vals, "name") + } + if s.SourceID.IsValue() { + vals = append(vals, "source_id") + } + if s.Checksum.IsValue() { + vals = append(vals, "checksum") + } + if s.Stored.IsValue() { + vals = append(vals, "stored") + } + if s.Accessionid.IsValue() { + vals = append(vals, "accessionid") + } + if s.Origin.IsValue() { + vals = append(vals, "origin") + } + if !s.PackageID.IsUnset() { + vals = append(vals, "package_id") + } + if s.SourcePackage.IsValue() { + vals = append(vals, "source_package") + } + return vals +} + +func (s LocationsFileSetter) Overwrite(t *LocationsFile) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UUID.IsValue() { + t.UUID = s.UUID.MustGet() + } + if s.Name.IsValue() { + t.Name = s.Name.MustGet() + } + if s.SourceID.IsValue() { + t.SourceID = s.SourceID.MustGet() + } + if s.Checksum.IsValue() { + t.Checksum = s.Checksum.MustGet() + } + if s.Stored.IsValue() { + t.Stored = s.Stored.MustGet() + } + if s.Accessionid.IsValue() { + t.Accessionid = s.Accessionid.MustGet() + } + if s.Origin.IsValue() { + t.Origin = s.Origin.MustGet() + } + if !s.PackageID.IsUnset() { + t.PackageID = s.PackageID.MustGetNull() + } + if s.SourcePackage.IsValue() { + t.SourcePackage = s.SourcePackage.MustGet() + } +} + +func (s *LocationsFileSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFiles.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UUID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UUID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Name.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Name.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SourceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SourceID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Checksum.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Checksum.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Stored.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Stored.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Accessionid.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Accessionid.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Origin.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Origin.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.PackageID.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PackageID.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SourcePackage.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SourcePackage.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsFileSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_file")...) +} + +func (s LocationsFileSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 10) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UUID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uuid")...), + mysql.Arg(s.UUID), + }}) + } + + if s.Name.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "name")...), + mysql.Arg(s.Name), + }}) + } + + if s.SourceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "source_id")...), + mysql.Arg(s.SourceID), + }}) + } + + if s.Checksum.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "checksum")...), + mysql.Arg(s.Checksum), + }}) + } + + if s.Stored.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "stored")...), + mysql.Arg(s.Stored), + }}) + } + + if s.Accessionid.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "accessionid")...), + mysql.Arg(s.Accessionid), + }}) + } + + if s.Origin.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "origin")...), + mysql.Arg(s.Origin), + }}) + } + + if !s.PackageID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "package_id")...), + mysql.Arg(s.PackageID), + }}) + } + + if s.SourcePackage.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "source_package")...), + mysql.Arg(s.SourcePackage), + }}) + } + + return exprs +} + +// FindLocationsFile retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsFile(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsFile, error) { + if len(cols) == 0 { + return LocationsFiles.Query( + sm.Where(LocationsFiles.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsFiles.Query( + sm.Where(LocationsFiles.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsFiles.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsFileExists checks the presence of a single record by primary key +func LocationsFileExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsFiles.Query( + sm.Where(LocationsFiles.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsFile is retrieved from the database +func (o *LocationsFile) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsFiles.AfterSelectHooks.RunHooks(ctx, exec, LocationsFileSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsFiles.AfterInsertHooks.RunHooks(ctx, exec, LocationsFileSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsFiles.AfterUpdateHooks.RunHooks(ctx, exec, LocationsFileSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsFiles.AfterDeleteHooks.RunHooks(ctx, exec, LocationsFileSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsFile +func (o *LocationsFile) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsFile) pkEQ() dialect.Expression { + return mysql.Quote("locations_file", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsFile +func (o *LocationsFile) Update(ctx context.Context, exec bob.Executor, s *LocationsFileSetter) error { + _, err := LocationsFiles.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsFile record with an executor +func (o *LocationsFile) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsFiles.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsFile using the executor +func (o *LocationsFile) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsFiles.Query( + sm.Where(LocationsFiles.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsFileSlice is retrieved from the database +func (o LocationsFileSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsFiles.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsFiles.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsFiles.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsFiles.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsFileSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_file", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsFileSlice) copyMatchingRows(from ...*LocationsFile) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsFileSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFiles.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsFile: + o.copyMatchingRows(retrieved) + case []*LocationsFile: + o.copyMatchingRows(retrieved...) + case LocationsFileSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsFile or a slice of LocationsFile + // then run the AfterUpdateHooks on the slice + _, err = LocationsFiles.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsFileSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFiles.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsFile: + o.copyMatchingRows(retrieved) + case []*LocationsFile: + o.copyMatchingRows(retrieved...) + case LocationsFileSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsFile or a slice of LocationsFile + // then run the AfterDeleteHooks on the slice + _, err = LocationsFiles.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsFileSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsFileSetter) error { + _, err := LocationsFiles.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsFileSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsFiles.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsFileSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsFiles.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// PackageLocationsPackage starts a query for related objects on locations_package +func (o *LocationsFile) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.ID.EQ(mysql.Arg(o.PackageID))), + )...) +} + +func (os LocationsFileSlice) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PackageID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsFilePackageLocationsPackage0(ctx context.Context, exec bob.Executor, count int, locationsFile0 *LocationsFile, locationsPackage1 *LocationsPackage) (*LocationsFile, error) { + setter := &LocationsFileSetter{ + PackageID: omitnull.From(locationsPackage1.ID), + } + + err := locationsFile0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsFilePackageLocationsPackage0: %w", err) + } + + return locationsFile0, nil +} + +func (locationsFile0 *LocationsFile) InsertPackageLocationsPackage(ctx context.Context, exec bob.Executor, related *LocationsPackageSetter) error { + var err error + + locationsPackage1, err := LocationsPackages.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsFilePackageLocationsPackage0(ctx, exec, 1, locationsFile0, locationsPackage1) + if err != nil { + return err + } + + locationsFile0.R.PackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.PackageLocationsFiles = append(locationsPackage1.R.PackageLocationsFiles, locationsFile0) + + return nil +} + +func (locationsFile0 *LocationsFile) AttachPackageLocationsPackage(ctx context.Context, exec bob.Executor, locationsPackage1 *LocationsPackage) error { + var err error + + _, err = attachLocationsFilePackageLocationsPackage0(ctx, exec, 1, locationsFile0, locationsPackage1) + if err != nil { + return err + } + + locationsFile0.R.PackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.PackageLocationsFiles = append(locationsPackage1.R.PackageLocationsFiles, locationsFile0) + + return nil +} + +type locationsFileWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UUID mysql.WhereMod[Q, string] + Name mysql.WhereMod[Q, string] + SourceID mysql.WhereMod[Q, string] + Checksum mysql.WhereMod[Q, string] + Stored mysql.WhereMod[Q, bool] + Accessionid mysql.WhereMod[Q, string] + Origin mysql.WhereMod[Q, string] + PackageID mysql.WhereNullMod[Q, int32] + SourcePackage mysql.WhereMod[Q, string] +} + +func (locationsFileWhere[Q]) AliasedAs(alias string) locationsFileWhere[Q] { + return buildLocationsFileWhere[Q](buildLocationsFileColumns(alias)) +} + +func buildLocationsFileWhere[Q mysql.Filterable](cols locationsFileColumns) locationsFileWhere[Q] { + return locationsFileWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UUID: mysql.Where[Q, string](cols.UUID), + Name: mysql.Where[Q, string](cols.Name), + SourceID: mysql.Where[Q, string](cols.SourceID), + Checksum: mysql.Where[Q, string](cols.Checksum), + Stored: mysql.Where[Q, bool](cols.Stored), + Accessionid: mysql.Where[Q, string](cols.Accessionid), + Origin: mysql.Where[Q, string](cols.Origin), + PackageID: mysql.WhereNull[Q, int32](cols.PackageID), + SourcePackage: mysql.Where[Q, string](cols.SourcePackage), + } +} + +func (o *LocationsFile) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "PackageLocationsPackage": + rel, ok := retrieved.(*LocationsPackage) + if !ok { + return fmt.Errorf("locationsFile cannot load %T as %q", retrieved, name) + } + + o.R.PackageLocationsPackage = rel + + if rel != nil { + rel.R.PackageLocationsFiles = LocationsFileSlice{o} + } + return nil + default: + return fmt.Errorf("locationsFile has no relationship %q", name) + } +} + +type locationsFilePreloader struct { + PackageLocationsPackage func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsFilePreloader() locationsFilePreloader { + return locationsFilePreloader{ + PackageLocationsPackage: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPackage, LocationsPackageSlice](mysql.PreloadRel{ + Name: "PackageLocationsPackage", + Sides: []mysql.PreloadSide{ + { + From: LocationsFiles, + To: LocationsPackages, + FromColumns: []string{"package_id"}, + ToColumns: []string{"id"}, + }, + }, + }, LocationsPackages.Columns.Names(), opts...) + }, + } +} + +type locationsFileThenLoader[Q orm.Loadable] struct { + PackageLocationsPackage func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsFileThenLoader[Q orm.Loadable]() locationsFileThenLoader[Q] { + type PackageLocationsPackageLoadInterface interface { + LoadPackageLocationsPackage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsFileThenLoader[Q]{ + PackageLocationsPackage: thenLoadBuilder[Q]( + "PackageLocationsPackage", + func(ctx context.Context, exec bob.Executor, retrieved PackageLocationsPackageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPackageLocationsPackage(ctx, exec, mods...) + }, + ), + } +} + +// LoadPackageLocationsPackage loads the locationsFile's PackageLocationsPackage into the .R struct +func (o *LocationsFile) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PackageLocationsPackage = nil + + related, err := o.PackageLocationsPackage(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PackageLocationsFiles = LocationsFileSlice{o} + + o.R.PackageLocationsPackage = related + return nil +} + +// LoadPackageLocationsPackage loads the locationsFile's PackageLocationsPackage into the .R struct +func (os LocationsFileSlice) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.PackageLocationsPackage(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + if !o.PackageID.IsValue() { + continue + } + + if !(o.PackageID.IsValue() && o.PackageID.MustGet() == rel.ID) { + continue + } + + rel.R.PackageLocationsFiles = append(rel.R.PackageLocationsFiles, o) + + o.R.PackageLocationsPackage = rel + break + } + } + + return nil +} + +type locationsFileJoins[Q dialect.Joinable] struct { + typ string + PackageLocationsPackage modAs[Q, locationsPackageColumns] +} + +func (j locationsFileJoins[Q]) aliasedAs(alias string) locationsFileJoins[Q] { + return buildLocationsFileJoins[Q](buildLocationsFileColumns(alias), j.typ) +} + +func buildLocationsFileJoins[Q dialect.Joinable](cols locationsFileColumns, typ string) locationsFileJoins[Q] { + return locationsFileJoins[Q]{ + typ: typ, + PackageLocationsPackage: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.ID.EQ(cols.PackageID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_fixitylog.bob.go b/database/storage_service/models/locations_fixitylog.bob.go new file mode 100644 index 0000000..4186f9a --- /dev/null +++ b/database/storage_service/models/locations_fixitylog.bob.go @@ -0,0 +1,667 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsFixitylog is an object representing the database table. +type LocationsFixitylog struct { + ID int32 `db:"id,pk,autoincr" ` + Success null.Val[bool] `db:"success" ` + ErrorDetails null.Val[string] `db:"error_details" ` + DatetimeReported time.Time `db:"datetime_reported" ` + PackageID string `db:"package_id" ` + + R locationsFixitylogR `db:"-" ` +} + +// LocationsFixitylogSlice is an alias for a slice of pointers to LocationsFixitylog. +// This should almost always be used instead of []*LocationsFixitylog. +type LocationsFixitylogSlice []*LocationsFixitylog + +// LocationsFixitylogs contains methods to work with the locations_fixitylog table +var LocationsFixitylogs = mysql.NewTablex[*LocationsFixitylog, LocationsFixitylogSlice, *LocationsFixitylogSetter]("locations_fixitylog", buildLocationsFixitylogColumns("locations_fixitylog"), []string{"id"}) + +// LocationsFixitylogsQuery is a query on the locations_fixitylog table +type LocationsFixitylogsQuery = *mysql.ViewQuery[*LocationsFixitylog, LocationsFixitylogSlice] + +// locationsFixitylogR is where relationships are stored. +type locationsFixitylogR struct { + PackageLocationsPackage *LocationsPackage // locations_fixitylog_package_id_0201e98f_fk_locations +} + +func buildLocationsFixitylogColumns(alias string) locationsFixitylogColumns { + return locationsFixitylogColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "success", "error_details", "datetime_reported", "package_id", + ).WithParent("locations_fixitylog"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Success: mysql.Quote(alias, "success"), + ErrorDetails: mysql.Quote(alias, "error_details"), + DatetimeReported: mysql.Quote(alias, "datetime_reported"), + PackageID: mysql.Quote(alias, "package_id"), + } +} + +type locationsFixitylogColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Success mysql.Expression + ErrorDetails mysql.Expression + DatetimeReported mysql.Expression + PackageID mysql.Expression +} + +func (c locationsFixitylogColumns) Alias() string { + return c.tableAlias +} + +func (locationsFixitylogColumns) AliasedAs(alias string) locationsFixitylogColumns { + return buildLocationsFixitylogColumns(alias) +} + +// LocationsFixitylogSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsFixitylogSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Success omitnull.Val[bool] `db:"success" ` + ErrorDetails omitnull.Val[string] `db:"error_details" ` + DatetimeReported omit.Val[time.Time] `db:"datetime_reported" ` + PackageID omit.Val[string] `db:"package_id" ` +} + +func (s LocationsFixitylogSetter) SetColumns() []string { + vals := make([]string, 0, 5) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if !s.Success.IsUnset() { + vals = append(vals, "success") + } + if !s.ErrorDetails.IsUnset() { + vals = append(vals, "error_details") + } + if s.DatetimeReported.IsValue() { + vals = append(vals, "datetime_reported") + } + if s.PackageID.IsValue() { + vals = append(vals, "package_id") + } + return vals +} + +func (s LocationsFixitylogSetter) Overwrite(t *LocationsFixitylog) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if !s.Success.IsUnset() { + t.Success = s.Success.MustGetNull() + } + if !s.ErrorDetails.IsUnset() { + t.ErrorDetails = s.ErrorDetails.MustGetNull() + } + if s.DatetimeReported.IsValue() { + t.DatetimeReported = s.DatetimeReported.MustGet() + } + if s.PackageID.IsValue() { + t.PackageID = s.PackageID.MustGet() + } +} + +func (s *LocationsFixitylogSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFixitylogs.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Success.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Success.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.ErrorDetails.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ErrorDetails.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DatetimeReported.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DatetimeReported.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.PackageID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PackageID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsFixitylogSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_fixitylog")...) +} + +func (s LocationsFixitylogSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 5) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if !s.Success.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "success")...), + mysql.Arg(s.Success), + }}) + } + + if !s.ErrorDetails.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "error_details")...), + mysql.Arg(s.ErrorDetails), + }}) + } + + if s.DatetimeReported.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "datetime_reported")...), + mysql.Arg(s.DatetimeReported), + }}) + } + + if s.PackageID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "package_id")...), + mysql.Arg(s.PackageID), + }}) + } + + return exprs +} + +// FindLocationsFixitylog retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsFixitylog(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsFixitylog, error) { + if len(cols) == 0 { + return LocationsFixitylogs.Query( + sm.Where(LocationsFixitylogs.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsFixitylogs.Query( + sm.Where(LocationsFixitylogs.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsFixitylogs.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsFixitylogExists checks the presence of a single record by primary key +func LocationsFixitylogExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsFixitylogs.Query( + sm.Where(LocationsFixitylogs.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsFixitylog is retrieved from the database +func (o *LocationsFixitylog) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsFixitylogs.AfterSelectHooks.RunHooks(ctx, exec, LocationsFixitylogSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsFixitylogs.AfterInsertHooks.RunHooks(ctx, exec, LocationsFixitylogSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsFixitylogs.AfterUpdateHooks.RunHooks(ctx, exec, LocationsFixitylogSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsFixitylogs.AfterDeleteHooks.RunHooks(ctx, exec, LocationsFixitylogSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsFixitylog +func (o *LocationsFixitylog) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsFixitylog) pkEQ() dialect.Expression { + return mysql.Quote("locations_fixitylog", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsFixitylog +func (o *LocationsFixitylog) Update(ctx context.Context, exec bob.Executor, s *LocationsFixitylogSetter) error { + _, err := LocationsFixitylogs.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsFixitylog record with an executor +func (o *LocationsFixitylog) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsFixitylogs.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsFixitylog using the executor +func (o *LocationsFixitylog) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsFixitylogs.Query( + sm.Where(LocationsFixitylogs.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsFixitylogSlice is retrieved from the database +func (o LocationsFixitylogSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsFixitylogs.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsFixitylogs.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsFixitylogs.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsFixitylogs.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsFixitylogSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_fixitylog", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsFixitylogSlice) copyMatchingRows(from ...*LocationsFixitylog) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsFixitylogSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFixitylogs.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsFixitylog: + o.copyMatchingRows(retrieved) + case []*LocationsFixitylog: + o.copyMatchingRows(retrieved...) + case LocationsFixitylogSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsFixitylog or a slice of LocationsFixitylog + // then run the AfterUpdateHooks on the slice + _, err = LocationsFixitylogs.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsFixitylogSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsFixitylogs.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsFixitylog: + o.copyMatchingRows(retrieved) + case []*LocationsFixitylog: + o.copyMatchingRows(retrieved...) + case LocationsFixitylogSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsFixitylog or a slice of LocationsFixitylog + // then run the AfterDeleteHooks on the slice + _, err = LocationsFixitylogs.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsFixitylogSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsFixitylogSetter) error { + _, err := LocationsFixitylogs.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsFixitylogSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsFixitylogs.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsFixitylogSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsFixitylogs.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// PackageLocationsPackage starts a query for related objects on locations_package +func (o *LocationsFixitylog) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.UUID.EQ(mysql.Arg(o.PackageID))), + )...) +} + +func (os LocationsFixitylogSlice) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PackageID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsFixitylogPackageLocationsPackage0(ctx context.Context, exec bob.Executor, count int, locationsFixitylog0 *LocationsFixitylog, locationsPackage1 *LocationsPackage) (*LocationsFixitylog, error) { + setter := &LocationsFixitylogSetter{ + PackageID: omit.From(locationsPackage1.UUID), + } + + err := locationsFixitylog0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsFixitylogPackageLocationsPackage0: %w", err) + } + + return locationsFixitylog0, nil +} + +func (locationsFixitylog0 *LocationsFixitylog) InsertPackageLocationsPackage(ctx context.Context, exec bob.Executor, related *LocationsPackageSetter) error { + var err error + + locationsPackage1, err := LocationsPackages.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsFixitylogPackageLocationsPackage0(ctx, exec, 1, locationsFixitylog0, locationsPackage1) + if err != nil { + return err + } + + locationsFixitylog0.R.PackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.PackageLocationsFixitylogs = append(locationsPackage1.R.PackageLocationsFixitylogs, locationsFixitylog0) + + return nil +} + +func (locationsFixitylog0 *LocationsFixitylog) AttachPackageLocationsPackage(ctx context.Context, exec bob.Executor, locationsPackage1 *LocationsPackage) error { + var err error + + _, err = attachLocationsFixitylogPackageLocationsPackage0(ctx, exec, 1, locationsFixitylog0, locationsPackage1) + if err != nil { + return err + } + + locationsFixitylog0.R.PackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.PackageLocationsFixitylogs = append(locationsPackage1.R.PackageLocationsFixitylogs, locationsFixitylog0) + + return nil +} + +type locationsFixitylogWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Success mysql.WhereNullMod[Q, bool] + ErrorDetails mysql.WhereNullMod[Q, string] + DatetimeReported mysql.WhereMod[Q, time.Time] + PackageID mysql.WhereMod[Q, string] +} + +func (locationsFixitylogWhere[Q]) AliasedAs(alias string) locationsFixitylogWhere[Q] { + return buildLocationsFixitylogWhere[Q](buildLocationsFixitylogColumns(alias)) +} + +func buildLocationsFixitylogWhere[Q mysql.Filterable](cols locationsFixitylogColumns) locationsFixitylogWhere[Q] { + return locationsFixitylogWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Success: mysql.WhereNull[Q, bool](cols.Success), + ErrorDetails: mysql.WhereNull[Q, string](cols.ErrorDetails), + DatetimeReported: mysql.Where[Q, time.Time](cols.DatetimeReported), + PackageID: mysql.Where[Q, string](cols.PackageID), + } +} + +func (o *LocationsFixitylog) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "PackageLocationsPackage": + rel, ok := retrieved.(*LocationsPackage) + if !ok { + return fmt.Errorf("locationsFixitylog cannot load %T as %q", retrieved, name) + } + + o.R.PackageLocationsPackage = rel + + if rel != nil { + rel.R.PackageLocationsFixitylogs = LocationsFixitylogSlice{o} + } + return nil + default: + return fmt.Errorf("locationsFixitylog has no relationship %q", name) + } +} + +type locationsFixitylogPreloader struct { + PackageLocationsPackage func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsFixitylogPreloader() locationsFixitylogPreloader { + return locationsFixitylogPreloader{ + PackageLocationsPackage: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPackage, LocationsPackageSlice](mysql.PreloadRel{ + Name: "PackageLocationsPackage", + Sides: []mysql.PreloadSide{ + { + From: LocationsFixitylogs, + To: LocationsPackages, + FromColumns: []string{"package_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsPackages.Columns.Names(), opts...) + }, + } +} + +type locationsFixitylogThenLoader[Q orm.Loadable] struct { + PackageLocationsPackage func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsFixitylogThenLoader[Q orm.Loadable]() locationsFixitylogThenLoader[Q] { + type PackageLocationsPackageLoadInterface interface { + LoadPackageLocationsPackage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsFixitylogThenLoader[Q]{ + PackageLocationsPackage: thenLoadBuilder[Q]( + "PackageLocationsPackage", + func(ctx context.Context, exec bob.Executor, retrieved PackageLocationsPackageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPackageLocationsPackage(ctx, exec, mods...) + }, + ), + } +} + +// LoadPackageLocationsPackage loads the locationsFixitylog's PackageLocationsPackage into the .R struct +func (o *LocationsFixitylog) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PackageLocationsPackage = nil + + related, err := o.PackageLocationsPackage(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PackageLocationsFixitylogs = LocationsFixitylogSlice{o} + + o.R.PackageLocationsPackage = related + return nil +} + +// LoadPackageLocationsPackage loads the locationsFixitylog's PackageLocationsPackage into the .R struct +func (os LocationsFixitylogSlice) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.PackageLocationsPackage(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !(o.PackageID == rel.UUID) { + continue + } + + rel.R.PackageLocationsFixitylogs = append(rel.R.PackageLocationsFixitylogs, o) + + o.R.PackageLocationsPackage = rel + break + } + } + + return nil +} + +type locationsFixitylogJoins[Q dialect.Joinable] struct { + typ string + PackageLocationsPackage modAs[Q, locationsPackageColumns] +} + +func (j locationsFixitylogJoins[Q]) aliasedAs(alias string) locationsFixitylogJoins[Q] { + return buildLocationsFixitylogJoins[Q](buildLocationsFixitylogColumns(alias), j.typ) +} + +func buildLocationsFixitylogJoins[Q dialect.Joinable](cols locationsFixitylogColumns, typ string) locationsFixitylogJoins[Q] { + return locationsFixitylogJoins[Q]{ + typ: typ, + PackageLocationsPackage: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.UUID.EQ(cols.PackageID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_gpg.bob.go b/database/storage_service/models/locations_gpg.bob.go new file mode 100644 index 0000000..1daeeb0 --- /dev/null +++ b/database/storage_service/models/locations_gpg.bob.go @@ -0,0 +1,616 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsGPG is an object representing the database table. +type LocationsGPG struct { + ID int32 `db:"id,pk,autoincr" ` + SpaceID string `db:"space_id" ` + Key string `db:"key" ` + + R locationsGPGR `db:"-" ` +} + +// LocationsGPGSlice is an alias for a slice of pointers to LocationsGPG. +// This should almost always be used instead of []*LocationsGPG. +type LocationsGPGSlice []*LocationsGPG + +// LocationsGPGS contains methods to work with the locations_gpg table +var LocationsGPGS = mysql.NewTablex[*LocationsGPG, LocationsGPGSlice, *LocationsGPGSetter]("locations_gpg", buildLocationsGPGColumns("locations_gpg"), []string{"id"}, []string{"space_id"}) + +// LocationsGPGSQuery is a query on the locations_gpg table +type LocationsGPGSQuery = *mysql.ViewQuery[*LocationsGPG, LocationsGPGSlice] + +// locationsGPGR is where relationships are stored. +type locationsGPGR struct { + SpaceLocationsSpace *LocationsSpace // locations_gpg_space_id_6223440d_fk_locations_space_uuid +} + +func buildLocationsGPGColumns(alias string) locationsGPGColumns { + return locationsGPGColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "space_id", "key", + ).WithParent("locations_gpg"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + SpaceID: mysql.Quote(alias, "space_id"), + Key: mysql.Quote(alias, "key"), + } +} + +type locationsGPGColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + SpaceID mysql.Expression + Key mysql.Expression +} + +func (c locationsGPGColumns) Alias() string { + return c.tableAlias +} + +func (locationsGPGColumns) AliasedAs(alias string) locationsGPGColumns { + return buildLocationsGPGColumns(alias) +} + +// LocationsGPGSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsGPGSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + SpaceID omit.Val[string] `db:"space_id" ` + Key omit.Val[string] `db:"key" ` +} + +func (s LocationsGPGSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + if s.Key.IsValue() { + vals = append(vals, "key") + } + return vals +} + +func (s LocationsGPGSetter) Overwrite(t *LocationsGPG) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } + if s.Key.IsValue() { + t.Key = s.Key.MustGet() + } +} + +func (s *LocationsGPGSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsGPGS.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Key.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Key.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsGPGSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_gpg")...) +} + +func (s LocationsGPGSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + if s.Key.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "key")...), + mysql.Arg(s.Key), + }}) + } + + return exprs +} + +// FindLocationsGPG retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsGPG(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsGPG, error) { + if len(cols) == 0 { + return LocationsGPGS.Query( + sm.Where(LocationsGPGS.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsGPGS.Query( + sm.Where(LocationsGPGS.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsGPGS.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsGPGExists checks the presence of a single record by primary key +func LocationsGPGExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsGPGS.Query( + sm.Where(LocationsGPGS.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsGPG is retrieved from the database +func (o *LocationsGPG) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsGPGS.AfterSelectHooks.RunHooks(ctx, exec, LocationsGPGSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsGPGS.AfterInsertHooks.RunHooks(ctx, exec, LocationsGPGSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsGPGS.AfterUpdateHooks.RunHooks(ctx, exec, LocationsGPGSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsGPGS.AfterDeleteHooks.RunHooks(ctx, exec, LocationsGPGSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsGPG +func (o *LocationsGPG) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsGPG) pkEQ() dialect.Expression { + return mysql.Quote("locations_gpg", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsGPG +func (o *LocationsGPG) Update(ctx context.Context, exec bob.Executor, s *LocationsGPGSetter) error { + _, err := LocationsGPGS.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsGPG record with an executor +func (o *LocationsGPG) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsGPGS.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsGPG using the executor +func (o *LocationsGPG) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsGPGS.Query( + sm.Where(LocationsGPGS.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsGPGSlice is retrieved from the database +func (o LocationsGPGSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsGPGS.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsGPGS.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsGPGS.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsGPGS.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsGPGSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_gpg", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsGPGSlice) copyMatchingRows(from ...*LocationsGPG) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsGPGSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsGPGS.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsGPG: + o.copyMatchingRows(retrieved) + case []*LocationsGPG: + o.copyMatchingRows(retrieved...) + case LocationsGPGSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsGPG or a slice of LocationsGPG + // then run the AfterUpdateHooks on the slice + _, err = LocationsGPGS.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsGPGSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsGPGS.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsGPG: + o.copyMatchingRows(retrieved) + case []*LocationsGPG: + o.copyMatchingRows(retrieved...) + case LocationsGPGSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsGPG or a slice of LocationsGPG + // then run the AfterDeleteHooks on the slice + _, err = LocationsGPGS.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsGPGSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsGPGSetter) error { + _, err := LocationsGPGS.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsGPGSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsGPGS.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsGPGSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsGPGS.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsGPG) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsGPGSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsGPGSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsGPG0 *LocationsGPG, locationsSpace1 *LocationsSpace) (*LocationsGPG, error) { + setter := &LocationsGPGSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsGPG0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsGPGSpaceLocationsSpace0: %w", err) + } + + return locationsGPG0, nil +} + +func (locationsGPG0 *LocationsGPG) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsGPGSpaceLocationsSpace0(ctx, exec, 1, locationsGPG0, locationsSpace1) + if err != nil { + return err + } + + locationsGPG0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsGPG = locationsGPG0 + + return nil +} + +func (locationsGPG0 *LocationsGPG) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsGPGSpaceLocationsSpace0(ctx, exec, 1, locationsGPG0, locationsSpace1) + if err != nil { + return err + } + + locationsGPG0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsGPG = locationsGPG0 + + return nil +} + +type locationsGPGWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + SpaceID mysql.WhereMod[Q, string] + Key mysql.WhereMod[Q, string] +} + +func (locationsGPGWhere[Q]) AliasedAs(alias string) locationsGPGWhere[Q] { + return buildLocationsGPGWhere[Q](buildLocationsGPGColumns(alias)) +} + +func buildLocationsGPGWhere[Q mysql.Filterable](cols locationsGPGColumns) locationsGPGWhere[Q] { + return locationsGPGWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + Key: mysql.Where[Q, string](cols.Key), + } +} + +func (o *LocationsGPG) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsGPG cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsGPG = o + } + return nil + default: + return fmt.Errorf("locationsGPG has no relationship %q", name) + } +} + +type locationsGPGPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsGPGPreloader() locationsGPGPreloader { + return locationsGPGPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsGPGS, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsGPGThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsGPGThenLoader[Q orm.Loadable]() locationsGPGThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsGPGThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsGPG's SpaceLocationsSpace into the .R struct +func (o *LocationsGPG) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsGPG = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsGPG's SpaceLocationsSpace into the .R struct +func (os LocationsGPGSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsGPG = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsGPGJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsGPGJoins[Q]) aliasedAs(alias string) locationsGPGJoins[Q] { + return buildLocationsGPGJoins[Q](buildLocationsGPGColumns(alias), j.typ) +} + +func buildLocationsGPGJoins[Q dialect.Joinable](cols locationsGPGColumns, typ string) locationsGPGJoins[Q] { + return locationsGPGJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_localfilesystem.bob.go b/database/storage_service/models/locations_localfilesystem.bob.go new file mode 100644 index 0000000..7d2c2fc --- /dev/null +++ b/database/storage_service/models/locations_localfilesystem.bob.go @@ -0,0 +1,592 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsLocalfilesystem is an object representing the database table. +type LocationsLocalfilesystem struct { + ID int32 `db:"id,pk,autoincr" ` + SpaceID string `db:"space_id" ` + + R locationsLocalfilesystemR `db:"-" ` +} + +// LocationsLocalfilesystemSlice is an alias for a slice of pointers to LocationsLocalfilesystem. +// This should almost always be used instead of []*LocationsLocalfilesystem. +type LocationsLocalfilesystemSlice []*LocationsLocalfilesystem + +// LocationsLocalfilesystems contains methods to work with the locations_localfilesystem table +var LocationsLocalfilesystems = mysql.NewTablex[*LocationsLocalfilesystem, LocationsLocalfilesystemSlice, *LocationsLocalfilesystemSetter]("locations_localfilesystem", buildLocationsLocalfilesystemColumns("locations_localfilesystem"), []string{"id"}, []string{"space_id"}) + +// LocationsLocalfilesystemsQuery is a query on the locations_localfilesystem table +type LocationsLocalfilesystemsQuery = *mysql.ViewQuery[*LocationsLocalfilesystem, LocationsLocalfilesystemSlice] + +// locationsLocalfilesystemR is where relationships are stored. +type locationsLocalfilesystemR struct { + SpaceLocationsSpace *LocationsSpace // locations_localfiles_space_id_a97d3d9f_fk_locations +} + +func buildLocationsLocalfilesystemColumns(alias string) locationsLocalfilesystemColumns { + return locationsLocalfilesystemColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "space_id", + ).WithParent("locations_localfilesystem"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsLocalfilesystemColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsLocalfilesystemColumns) Alias() string { + return c.tableAlias +} + +func (locationsLocalfilesystemColumns) AliasedAs(alias string) locationsLocalfilesystemColumns { + return buildLocationsLocalfilesystemColumns(alias) +} + +// LocationsLocalfilesystemSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsLocalfilesystemSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsLocalfilesystemSetter) SetColumns() []string { + vals := make([]string, 0, 2) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsLocalfilesystemSetter) Overwrite(t *LocationsLocalfilesystem) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsLocalfilesystemSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocalfilesystems.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsLocalfilesystemSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_localfilesystem")...) +} + +func (s LocationsLocalfilesystemSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 2) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsLocalfilesystem retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsLocalfilesystem(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsLocalfilesystem, error) { + if len(cols) == 0 { + return LocationsLocalfilesystems.Query( + sm.Where(LocationsLocalfilesystems.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsLocalfilesystems.Query( + sm.Where(LocationsLocalfilesystems.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsLocalfilesystems.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsLocalfilesystemExists checks the presence of a single record by primary key +func LocationsLocalfilesystemExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsLocalfilesystems.Query( + sm.Where(LocationsLocalfilesystems.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsLocalfilesystem is retrieved from the database +func (o *LocationsLocalfilesystem) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLocalfilesystems.AfterSelectHooks.RunHooks(ctx, exec, LocationsLocalfilesystemSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsLocalfilesystems.AfterInsertHooks.RunHooks(ctx, exec, LocationsLocalfilesystemSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsLocalfilesystems.AfterUpdateHooks.RunHooks(ctx, exec, LocationsLocalfilesystemSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsLocalfilesystems.AfterDeleteHooks.RunHooks(ctx, exec, LocationsLocalfilesystemSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsLocalfilesystem +func (o *LocationsLocalfilesystem) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsLocalfilesystem) pkEQ() dialect.Expression { + return mysql.Quote("locations_localfilesystem", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsLocalfilesystem +func (o *LocationsLocalfilesystem) Update(ctx context.Context, exec bob.Executor, s *LocationsLocalfilesystemSetter) error { + _, err := LocationsLocalfilesystems.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsLocalfilesystem record with an executor +func (o *LocationsLocalfilesystem) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsLocalfilesystems.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsLocalfilesystem using the executor +func (o *LocationsLocalfilesystem) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsLocalfilesystems.Query( + sm.Where(LocationsLocalfilesystems.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsLocalfilesystemSlice is retrieved from the database +func (o LocationsLocalfilesystemSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLocalfilesystems.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsLocalfilesystems.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsLocalfilesystems.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsLocalfilesystems.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsLocalfilesystemSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_localfilesystem", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsLocalfilesystemSlice) copyMatchingRows(from ...*LocationsLocalfilesystem) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsLocalfilesystemSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocalfilesystems.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLocalfilesystem: + o.copyMatchingRows(retrieved) + case []*LocationsLocalfilesystem: + o.copyMatchingRows(retrieved...) + case LocationsLocalfilesystemSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLocalfilesystem or a slice of LocationsLocalfilesystem + // then run the AfterUpdateHooks on the slice + _, err = LocationsLocalfilesystems.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsLocalfilesystemSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocalfilesystems.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLocalfilesystem: + o.copyMatchingRows(retrieved) + case []*LocationsLocalfilesystem: + o.copyMatchingRows(retrieved...) + case LocationsLocalfilesystemSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLocalfilesystem or a slice of LocationsLocalfilesystem + // then run the AfterDeleteHooks on the slice + _, err = LocationsLocalfilesystems.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsLocalfilesystemSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsLocalfilesystemSetter) error { + _, err := LocationsLocalfilesystems.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsLocalfilesystemSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsLocalfilesystems.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsLocalfilesystemSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsLocalfilesystems.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsLocalfilesystem) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsLocalfilesystemSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsLocalfilesystemSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsLocalfilesystem0 *LocationsLocalfilesystem, locationsSpace1 *LocationsSpace) (*LocationsLocalfilesystem, error) { + setter := &LocationsLocalfilesystemSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsLocalfilesystem0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocalfilesystemSpaceLocationsSpace0: %w", err) + } + + return locationsLocalfilesystem0, nil +} + +func (locationsLocalfilesystem0 *LocationsLocalfilesystem) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsLocalfilesystemSpaceLocationsSpace0(ctx, exec, 1, locationsLocalfilesystem0, locationsSpace1) + if err != nil { + return err + } + + locationsLocalfilesystem0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsLocalfilesystem = locationsLocalfilesystem0 + + return nil +} + +func (locationsLocalfilesystem0 *LocationsLocalfilesystem) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsLocalfilesystemSpaceLocationsSpace0(ctx, exec, 1, locationsLocalfilesystem0, locationsSpace1) + if err != nil { + return err + } + + locationsLocalfilesystem0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsLocalfilesystem = locationsLocalfilesystem0 + + return nil +} + +type locationsLocalfilesystemWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsLocalfilesystemWhere[Q]) AliasedAs(alias string) locationsLocalfilesystemWhere[Q] { + return buildLocationsLocalfilesystemWhere[Q](buildLocationsLocalfilesystemColumns(alias)) +} + +func buildLocationsLocalfilesystemWhere[Q mysql.Filterable](cols locationsLocalfilesystemColumns) locationsLocalfilesystemWhere[Q] { + return locationsLocalfilesystemWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsLocalfilesystem) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsLocalfilesystem cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsLocalfilesystem = o + } + return nil + default: + return fmt.Errorf("locationsLocalfilesystem has no relationship %q", name) + } +} + +type locationsLocalfilesystemPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsLocalfilesystemPreloader() locationsLocalfilesystemPreloader { + return locationsLocalfilesystemPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsLocalfilesystems, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsLocalfilesystemThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsLocalfilesystemThenLoader[Q orm.Loadable]() locationsLocalfilesystemThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsLocalfilesystemThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsLocalfilesystem's SpaceLocationsSpace into the .R struct +func (o *LocationsLocalfilesystem) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsLocalfilesystem = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsLocalfilesystem's SpaceLocationsSpace into the .R struct +func (os LocationsLocalfilesystemSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsLocalfilesystem = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsLocalfilesystemJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsLocalfilesystemJoins[Q]) aliasedAs(alias string) locationsLocalfilesystemJoins[Q] { + return buildLocationsLocalfilesystemJoins[Q](buildLocationsLocalfilesystemColumns(alias), j.typ) +} + +func buildLocationsLocalfilesystemJoins[Q dialect.Joinable](cols locationsLocalfilesystemColumns, typ string) locationsLocalfilesystemJoins[Q] { + return locationsLocalfilesystemJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_location.bob.go b/database/storage_service/models/locations_location.bob.go new file mode 100644 index 0000000..bc6fb21 --- /dev/null +++ b/database/storage_service/models/locations_location.bob.go @@ -0,0 +1,1705 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsLocation is an object representing the database table. +type LocationsLocation struct { + ID int32 `db:"id,pk,autoincr" ` + UUID string `db:"uuid" ` + Purpose string `db:"purpose" ` + RelativePath string `db:"relative_path" ` + Description null.Val[string] `db:"description" ` + Quota null.Val[int64] `db:"quota" ` + Used int64 `db:"used" ` + Enabled bool `db:"enabled" ` + SpaceID string `db:"space_id" ` + + R locationsLocationR `db:"-" ` +} + +// LocationsLocationSlice is an alias for a slice of pointers to LocationsLocation. +// This should almost always be used instead of []*LocationsLocation. +type LocationsLocationSlice []*LocationsLocation + +// LocationsLocations contains methods to work with the locations_location table +var LocationsLocations = mysql.NewTablex[*LocationsLocation, LocationsLocationSlice, *LocationsLocationSetter]("locations_location", buildLocationsLocationColumns("locations_location"), []string{"id"}, []string{"uuid"}) + +// LocationsLocationsQuery is a query on the locations_location table +type LocationsLocationsQuery = *mysql.ViewQuery[*LocationsLocation, LocationsLocationSlice] + +// locationsLocationR is where relationships are stored. +type locationsLocationR struct { + FromLocationLocationsLocationReplicators LocationsLocationReplicatorSlice // locations_location_r_from_location_id_3b9a55f5_fk_locations + ToLocationLocationsLocationReplicators LocationsLocationReplicatorSlice // locations_location_r_to_location_id_27be9af1_fk_locations + SpaceLocationsSpace *LocationsSpace // locations_location_space_id_748845a7_fk_locations_space_uuid + LocationLocationsLocationpipelines LocationsLocationpipelineSlice // locations_locationpi_location_id_1bff2f57_fk_locations + CurrentLocationLocationsPackages LocationsPackageSlice // locations_package_current_location_id_c8f7daee_fk_locations + PointerFileLocationLocationsPackages LocationsPackageSlice // locations_package_pointer_file_locatio_2adf5d3c_fk_locations +} + +func buildLocationsLocationColumns(alias string) locationsLocationColumns { + return locationsLocationColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "uuid", "purpose", "relative_path", "description", "quota", "used", "enabled", "space_id", + ).WithParent("locations_location"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UUID: mysql.Quote(alias, "uuid"), + Purpose: mysql.Quote(alias, "purpose"), + RelativePath: mysql.Quote(alias, "relative_path"), + Description: mysql.Quote(alias, "description"), + Quota: mysql.Quote(alias, "quota"), + Used: mysql.Quote(alias, "used"), + Enabled: mysql.Quote(alias, "enabled"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsLocationColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UUID mysql.Expression + Purpose mysql.Expression + RelativePath mysql.Expression + Description mysql.Expression + Quota mysql.Expression + Used mysql.Expression + Enabled mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsLocationColumns) Alias() string { + return c.tableAlias +} + +func (locationsLocationColumns) AliasedAs(alias string) locationsLocationColumns { + return buildLocationsLocationColumns(alias) +} + +// LocationsLocationSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsLocationSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UUID omit.Val[string] `db:"uuid" ` + Purpose omit.Val[string] `db:"purpose" ` + RelativePath omit.Val[string] `db:"relative_path" ` + Description omitnull.Val[string] `db:"description" ` + Quota omitnull.Val[int64] `db:"quota" ` + Used omit.Val[int64] `db:"used" ` + Enabled omit.Val[bool] `db:"enabled" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsLocationSetter) SetColumns() []string { + vals := make([]string, 0, 9) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UUID.IsValue() { + vals = append(vals, "uuid") + } + if s.Purpose.IsValue() { + vals = append(vals, "purpose") + } + if s.RelativePath.IsValue() { + vals = append(vals, "relative_path") + } + if !s.Description.IsUnset() { + vals = append(vals, "description") + } + if !s.Quota.IsUnset() { + vals = append(vals, "quota") + } + if s.Used.IsValue() { + vals = append(vals, "used") + } + if s.Enabled.IsValue() { + vals = append(vals, "enabled") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsLocationSetter) Overwrite(t *LocationsLocation) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UUID.IsValue() { + t.UUID = s.UUID.MustGet() + } + if s.Purpose.IsValue() { + t.Purpose = s.Purpose.MustGet() + } + if s.RelativePath.IsValue() { + t.RelativePath = s.RelativePath.MustGet() + } + if !s.Description.IsUnset() { + t.Description = s.Description.MustGetNull() + } + if !s.Quota.IsUnset() { + t.Quota = s.Quota.MustGetNull() + } + if s.Used.IsValue() { + t.Used = s.Used.MustGet() + } + if s.Enabled.IsValue() { + t.Enabled = s.Enabled.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsLocationSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocations.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UUID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UUID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Purpose.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Purpose.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.RelativePath.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RelativePath.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Description.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Description.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Quota.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Quota.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Used.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Used.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Enabled.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Enabled.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsLocationSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_location")...) +} + +func (s LocationsLocationSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 9) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UUID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uuid")...), + mysql.Arg(s.UUID), + }}) + } + + if s.Purpose.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "purpose")...), + mysql.Arg(s.Purpose), + }}) + } + + if s.RelativePath.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "relative_path")...), + mysql.Arg(s.RelativePath), + }}) + } + + if !s.Description.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "description")...), + mysql.Arg(s.Description), + }}) + } + + if !s.Quota.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "quota")...), + mysql.Arg(s.Quota), + }}) + } + + if s.Used.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "used")...), + mysql.Arg(s.Used), + }}) + } + + if s.Enabled.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "enabled")...), + mysql.Arg(s.Enabled), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsLocation retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsLocation(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsLocation, error) { + if len(cols) == 0 { + return LocationsLocations.Query( + sm.Where(LocationsLocations.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsLocations.Query( + sm.Where(LocationsLocations.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsLocations.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsLocationExists checks the presence of a single record by primary key +func LocationsLocationExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsLocations.Query( + sm.Where(LocationsLocations.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsLocation is retrieved from the database +func (o *LocationsLocation) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLocations.AfterSelectHooks.RunHooks(ctx, exec, LocationsLocationSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsLocations.AfterInsertHooks.RunHooks(ctx, exec, LocationsLocationSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsLocations.AfterUpdateHooks.RunHooks(ctx, exec, LocationsLocationSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsLocations.AfterDeleteHooks.RunHooks(ctx, exec, LocationsLocationSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsLocation +func (o *LocationsLocation) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsLocation) pkEQ() dialect.Expression { + return mysql.Quote("locations_location", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsLocation +func (o *LocationsLocation) Update(ctx context.Context, exec bob.Executor, s *LocationsLocationSetter) error { + _, err := LocationsLocations.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsLocation record with an executor +func (o *LocationsLocation) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsLocations.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsLocation using the executor +func (o *LocationsLocation) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsLocations.Query( + sm.Where(LocationsLocations.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsLocationSlice is retrieved from the database +func (o LocationsLocationSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLocations.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsLocations.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsLocations.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsLocations.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsLocationSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_location", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsLocationSlice) copyMatchingRows(from ...*LocationsLocation) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsLocationSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocations.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLocation: + o.copyMatchingRows(retrieved) + case []*LocationsLocation: + o.copyMatchingRows(retrieved...) + case LocationsLocationSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLocation or a slice of LocationsLocation + // then run the AfterUpdateHooks on the slice + _, err = LocationsLocations.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsLocationSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocations.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLocation: + o.copyMatchingRows(retrieved) + case []*LocationsLocation: + o.copyMatchingRows(retrieved...) + case LocationsLocationSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLocation or a slice of LocationsLocation + // then run the AfterDeleteHooks on the slice + _, err = LocationsLocations.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsLocationSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsLocationSetter) error { + _, err := LocationsLocations.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsLocationSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsLocations.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsLocationSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsLocations.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// FromLocationLocationsLocationReplicators starts a query for related objects on locations_location_replicators +func (o *LocationsLocation) FromLocationLocationsLocationReplicators(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationReplicatorsQuery { + return LocationsLocationReplicators.Query(append(mods, + sm.Where(LocationsLocationReplicators.Columns.FromLocationID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os LocationsLocationSlice) FromLocationLocationsLocationReplicators(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationReplicatorsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocationReplicators.Query(append(mods, + sm.Where(mysql.Group(LocationsLocationReplicators.Columns.FromLocationID).OP("IN", PKArgExpr)), + )...) +} + +// ToLocationLocationsLocationReplicators starts a query for related objects on locations_location_replicators +func (o *LocationsLocation) ToLocationLocationsLocationReplicators(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationReplicatorsQuery { + return LocationsLocationReplicators.Query(append(mods, + sm.Where(LocationsLocationReplicators.Columns.ToLocationID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os LocationsLocationSlice) ToLocationLocationsLocationReplicators(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationReplicatorsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocationReplicators.Query(append(mods, + sm.Where(mysql.Group(LocationsLocationReplicators.Columns.ToLocationID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsLocation) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsLocationSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +// LocationLocationsLocationpipelines starts a query for related objects on locations_locationpipeline +func (o *LocationsLocation) LocationLocationsLocationpipelines(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationpipelinesQuery { + return LocationsLocationpipelines.Query(append(mods, + sm.Where(LocationsLocationpipelines.Columns.LocationID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsLocationSlice) LocationLocationsLocationpipelines(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationpipelinesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocationpipelines.Query(append(mods, + sm.Where(mysql.Group(LocationsLocationpipelines.Columns.LocationID).OP("IN", PKArgExpr)), + )...) +} + +// CurrentLocationLocationsPackages starts a query for related objects on locations_package +func (o *LocationsLocation) CurrentLocationLocationsPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.CurrentLocationID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsLocationSlice) CurrentLocationLocationsPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.CurrentLocationID).OP("IN", PKArgExpr)), + )...) +} + +// PointerFileLocationLocationsPackages starts a query for related objects on locations_package +func (o *LocationsLocation) PointerFileLocationLocationsPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.PointerFileLocationID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsLocationSlice) PointerFileLocationLocationsPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.PointerFileLocationID).OP("IN", PKArgExpr)), + )...) +} + +func insertLocationsLocationFromLocationLocationsLocationReplicators0(ctx context.Context, exec bob.Executor, locationsLocationReplicators1 []*LocationsLocationReplicatorSetter, locationsLocation0 *LocationsLocation) (LocationsLocationReplicatorSlice, error) { + for i := range locationsLocationReplicators1 { + locationsLocationReplicators1[i].FromLocationID = omit.From(locationsLocation0.ID) + } + + ret, err := LocationsLocationReplicators.Insert(bob.ToMods(locationsLocationReplicators1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsLocationFromLocationLocationsLocationReplicators0: %w", err) + } + + return ret, nil +} + +func attachLocationsLocationFromLocationLocationsLocationReplicators0(ctx context.Context, exec bob.Executor, count int, locationsLocationReplicators1 LocationsLocationReplicatorSlice, locationsLocation0 *LocationsLocation) (LocationsLocationReplicatorSlice, error) { + setter := &LocationsLocationReplicatorSetter{ + FromLocationID: omit.From(locationsLocation0.ID), + } + + err := locationsLocationReplicators1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationFromLocationLocationsLocationReplicators0: %w", err) + } + + return locationsLocationReplicators1, nil +} + +func (locationsLocation0 *LocationsLocation) InsertFromLocationLocationsLocationReplicators(ctx context.Context, exec bob.Executor, related ...*LocationsLocationReplicatorSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsLocationReplicators1, err := insertLocationsLocationFromLocationLocationsLocationReplicators0(ctx, exec, related, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.FromLocationLocationsLocationReplicators = append(locationsLocation0.R.FromLocationLocationsLocationReplicators, locationsLocationReplicators1...) + + for _, rel := range locationsLocationReplicators1 { + rel.R.FromLocationLocationsLocation = locationsLocation0 + } + return nil +} + +func (locationsLocation0 *LocationsLocation) AttachFromLocationLocationsLocationReplicators(ctx context.Context, exec bob.Executor, related ...*LocationsLocationReplicator) error { + if len(related) == 0 { + return nil + } + + var err error + locationsLocationReplicators1 := LocationsLocationReplicatorSlice(related) + + _, err = attachLocationsLocationFromLocationLocationsLocationReplicators0(ctx, exec, len(related), locationsLocationReplicators1, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.FromLocationLocationsLocationReplicators = append(locationsLocation0.R.FromLocationLocationsLocationReplicators, locationsLocationReplicators1...) + + for _, rel := range related { + rel.R.FromLocationLocationsLocation = locationsLocation0 + } + + return nil +} + +func insertLocationsLocationToLocationLocationsLocationReplicators0(ctx context.Context, exec bob.Executor, locationsLocationReplicators1 []*LocationsLocationReplicatorSetter, locationsLocation0 *LocationsLocation) (LocationsLocationReplicatorSlice, error) { + for i := range locationsLocationReplicators1 { + locationsLocationReplicators1[i].ToLocationID = omit.From(locationsLocation0.ID) + } + + ret, err := LocationsLocationReplicators.Insert(bob.ToMods(locationsLocationReplicators1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsLocationToLocationLocationsLocationReplicators0: %w", err) + } + + return ret, nil +} + +func attachLocationsLocationToLocationLocationsLocationReplicators0(ctx context.Context, exec bob.Executor, count int, locationsLocationReplicators1 LocationsLocationReplicatorSlice, locationsLocation0 *LocationsLocation) (LocationsLocationReplicatorSlice, error) { + setter := &LocationsLocationReplicatorSetter{ + ToLocationID: omit.From(locationsLocation0.ID), + } + + err := locationsLocationReplicators1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationToLocationLocationsLocationReplicators0: %w", err) + } + + return locationsLocationReplicators1, nil +} + +func (locationsLocation0 *LocationsLocation) InsertToLocationLocationsLocationReplicators(ctx context.Context, exec bob.Executor, related ...*LocationsLocationReplicatorSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsLocationReplicators1, err := insertLocationsLocationToLocationLocationsLocationReplicators0(ctx, exec, related, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.ToLocationLocationsLocationReplicators = append(locationsLocation0.R.ToLocationLocationsLocationReplicators, locationsLocationReplicators1...) + + for _, rel := range locationsLocationReplicators1 { + rel.R.ToLocationLocationsLocation = locationsLocation0 + } + return nil +} + +func (locationsLocation0 *LocationsLocation) AttachToLocationLocationsLocationReplicators(ctx context.Context, exec bob.Executor, related ...*LocationsLocationReplicator) error { + if len(related) == 0 { + return nil + } + + var err error + locationsLocationReplicators1 := LocationsLocationReplicatorSlice(related) + + _, err = attachLocationsLocationToLocationLocationsLocationReplicators0(ctx, exec, len(related), locationsLocationReplicators1, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.ToLocationLocationsLocationReplicators = append(locationsLocation0.R.ToLocationLocationsLocationReplicators, locationsLocationReplicators1...) + + for _, rel := range related { + rel.R.ToLocationLocationsLocation = locationsLocation0 + } + + return nil +} + +func attachLocationsLocationSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsLocation0 *LocationsLocation, locationsSpace1 *LocationsSpace) (*LocationsLocation, error) { + setter := &LocationsLocationSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsLocation0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationSpaceLocationsSpace0: %w", err) + } + + return locationsLocation0, nil +} + +func (locationsLocation0 *LocationsLocation) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsLocationSpaceLocationsSpace0(ctx, exec, 1, locationsLocation0, locationsSpace1) + if err != nil { + return err + } + + locationsLocation0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsLocations = append(locationsSpace1.R.SpaceLocationsLocations, locationsLocation0) + + return nil +} + +func (locationsLocation0 *LocationsLocation) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsLocationSpaceLocationsSpace0(ctx, exec, 1, locationsLocation0, locationsSpace1) + if err != nil { + return err + } + + locationsLocation0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsLocations = append(locationsSpace1.R.SpaceLocationsLocations, locationsLocation0) + + return nil +} + +func insertLocationsLocationLocationLocationsLocationpipelines0(ctx context.Context, exec bob.Executor, locationsLocationpipelines1 []*LocationsLocationpipelineSetter, locationsLocation0 *LocationsLocation) (LocationsLocationpipelineSlice, error) { + for i := range locationsLocationpipelines1 { + locationsLocationpipelines1[i].LocationID = omit.From(locationsLocation0.UUID) + } + + ret, err := LocationsLocationpipelines.Insert(bob.ToMods(locationsLocationpipelines1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsLocationLocationLocationsLocationpipelines0: %w", err) + } + + return ret, nil +} + +func attachLocationsLocationLocationLocationsLocationpipelines0(ctx context.Context, exec bob.Executor, count int, locationsLocationpipelines1 LocationsLocationpipelineSlice, locationsLocation0 *LocationsLocation) (LocationsLocationpipelineSlice, error) { + setter := &LocationsLocationpipelineSetter{ + LocationID: omit.From(locationsLocation0.UUID), + } + + err := locationsLocationpipelines1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationLocationLocationsLocationpipelines0: %w", err) + } + + return locationsLocationpipelines1, nil +} + +func (locationsLocation0 *LocationsLocation) InsertLocationLocationsLocationpipelines(ctx context.Context, exec bob.Executor, related ...*LocationsLocationpipelineSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsLocationpipelines1, err := insertLocationsLocationLocationLocationsLocationpipelines0(ctx, exec, related, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.LocationLocationsLocationpipelines = append(locationsLocation0.R.LocationLocationsLocationpipelines, locationsLocationpipelines1...) + + for _, rel := range locationsLocationpipelines1 { + rel.R.LocationLocationsLocation = locationsLocation0 + } + return nil +} + +func (locationsLocation0 *LocationsLocation) AttachLocationLocationsLocationpipelines(ctx context.Context, exec bob.Executor, related ...*LocationsLocationpipeline) error { + if len(related) == 0 { + return nil + } + + var err error + locationsLocationpipelines1 := LocationsLocationpipelineSlice(related) + + _, err = attachLocationsLocationLocationLocationsLocationpipelines0(ctx, exec, len(related), locationsLocationpipelines1, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.LocationLocationsLocationpipelines = append(locationsLocation0.R.LocationLocationsLocationpipelines, locationsLocationpipelines1...) + + for _, rel := range related { + rel.R.LocationLocationsLocation = locationsLocation0 + } + + return nil +} + +func insertLocationsLocationCurrentLocationLocationsPackages0(ctx context.Context, exec bob.Executor, locationsPackages1 []*LocationsPackageSetter, locationsLocation0 *LocationsLocation) (LocationsPackageSlice, error) { + for i := range locationsPackages1 { + locationsPackages1[i].CurrentLocationID = omit.From(locationsLocation0.UUID) + } + + ret, err := LocationsPackages.Insert(bob.ToMods(locationsPackages1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsLocationCurrentLocationLocationsPackages0: %w", err) + } + + return ret, nil +} + +func attachLocationsLocationCurrentLocationLocationsPackages0(ctx context.Context, exec bob.Executor, count int, locationsPackages1 LocationsPackageSlice, locationsLocation0 *LocationsLocation) (LocationsPackageSlice, error) { + setter := &LocationsPackageSetter{ + CurrentLocationID: omit.From(locationsLocation0.UUID), + } + + err := locationsPackages1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationCurrentLocationLocationsPackages0: %w", err) + } + + return locationsPackages1, nil +} + +func (locationsLocation0 *LocationsLocation) InsertCurrentLocationLocationsPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackageSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsPackages1, err := insertLocationsLocationCurrentLocationLocationsPackages0(ctx, exec, related, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.CurrentLocationLocationsPackages = append(locationsLocation0.R.CurrentLocationLocationsPackages, locationsPackages1...) + + for _, rel := range locationsPackages1 { + rel.R.CurrentLocationLocationsLocation = locationsLocation0 + } + return nil +} + +func (locationsLocation0 *LocationsLocation) AttachCurrentLocationLocationsPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackage) error { + if len(related) == 0 { + return nil + } + + var err error + locationsPackages1 := LocationsPackageSlice(related) + + _, err = attachLocationsLocationCurrentLocationLocationsPackages0(ctx, exec, len(related), locationsPackages1, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.CurrentLocationLocationsPackages = append(locationsLocation0.R.CurrentLocationLocationsPackages, locationsPackages1...) + + for _, rel := range related { + rel.R.CurrentLocationLocationsLocation = locationsLocation0 + } + + return nil +} + +func insertLocationsLocationPointerFileLocationLocationsPackages0(ctx context.Context, exec bob.Executor, locationsPackages1 []*LocationsPackageSetter, locationsLocation0 *LocationsLocation) (LocationsPackageSlice, error) { + for i := range locationsPackages1 { + locationsPackages1[i].PointerFileLocationID = omitnull.From(locationsLocation0.UUID) + } + + ret, err := LocationsPackages.Insert(bob.ToMods(locationsPackages1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsLocationPointerFileLocationLocationsPackages0: %w", err) + } + + return ret, nil +} + +func attachLocationsLocationPointerFileLocationLocationsPackages0(ctx context.Context, exec bob.Executor, count int, locationsPackages1 LocationsPackageSlice, locationsLocation0 *LocationsLocation) (LocationsPackageSlice, error) { + setter := &LocationsPackageSetter{ + PointerFileLocationID: omitnull.From(locationsLocation0.UUID), + } + + err := locationsPackages1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationPointerFileLocationLocationsPackages0: %w", err) + } + + return locationsPackages1, nil +} + +func (locationsLocation0 *LocationsLocation) InsertPointerFileLocationLocationsPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackageSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsPackages1, err := insertLocationsLocationPointerFileLocationLocationsPackages0(ctx, exec, related, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.PointerFileLocationLocationsPackages = append(locationsLocation0.R.PointerFileLocationLocationsPackages, locationsPackages1...) + + for _, rel := range locationsPackages1 { + rel.R.PointerFileLocationLocationsLocation = locationsLocation0 + } + return nil +} + +func (locationsLocation0 *LocationsLocation) AttachPointerFileLocationLocationsPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackage) error { + if len(related) == 0 { + return nil + } + + var err error + locationsPackages1 := LocationsPackageSlice(related) + + _, err = attachLocationsLocationPointerFileLocationLocationsPackages0(ctx, exec, len(related), locationsPackages1, locationsLocation0) + if err != nil { + return err + } + + locationsLocation0.R.PointerFileLocationLocationsPackages = append(locationsLocation0.R.PointerFileLocationLocationsPackages, locationsPackages1...) + + for _, rel := range related { + rel.R.PointerFileLocationLocationsLocation = locationsLocation0 + } + + return nil +} + +type locationsLocationWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UUID mysql.WhereMod[Q, string] + Purpose mysql.WhereMod[Q, string] + RelativePath mysql.WhereMod[Q, string] + Description mysql.WhereNullMod[Q, string] + Quota mysql.WhereNullMod[Q, int64] + Used mysql.WhereMod[Q, int64] + Enabled mysql.WhereMod[Q, bool] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsLocationWhere[Q]) AliasedAs(alias string) locationsLocationWhere[Q] { + return buildLocationsLocationWhere[Q](buildLocationsLocationColumns(alias)) +} + +func buildLocationsLocationWhere[Q mysql.Filterable](cols locationsLocationColumns) locationsLocationWhere[Q] { + return locationsLocationWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UUID: mysql.Where[Q, string](cols.UUID), + Purpose: mysql.Where[Q, string](cols.Purpose), + RelativePath: mysql.Where[Q, string](cols.RelativePath), + Description: mysql.WhereNull[Q, string](cols.Description), + Quota: mysql.WhereNull[Q, int64](cols.Quota), + Used: mysql.Where[Q, int64](cols.Used), + Enabled: mysql.Where[Q, bool](cols.Enabled), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsLocation) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "FromLocationLocationsLocationReplicators": + rels, ok := retrieved.(LocationsLocationReplicatorSlice) + if !ok { + return fmt.Errorf("locationsLocation cannot load %T as %q", retrieved, name) + } + + o.R.FromLocationLocationsLocationReplicators = rels + + for _, rel := range rels { + if rel != nil { + rel.R.FromLocationLocationsLocation = o + } + } + return nil + case "ToLocationLocationsLocationReplicators": + rels, ok := retrieved.(LocationsLocationReplicatorSlice) + if !ok { + return fmt.Errorf("locationsLocation cannot load %T as %q", retrieved, name) + } + + o.R.ToLocationLocationsLocationReplicators = rels + + for _, rel := range rels { + if rel != nil { + rel.R.ToLocationLocationsLocation = o + } + } + return nil + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsLocation cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsLocations = LocationsLocationSlice{o} + } + return nil + case "LocationLocationsLocationpipelines": + rels, ok := retrieved.(LocationsLocationpipelineSlice) + if !ok { + return fmt.Errorf("locationsLocation cannot load %T as %q", retrieved, name) + } + + o.R.LocationLocationsLocationpipelines = rels + + for _, rel := range rels { + if rel != nil { + rel.R.LocationLocationsLocation = o + } + } + return nil + case "CurrentLocationLocationsPackages": + rels, ok := retrieved.(LocationsPackageSlice) + if !ok { + return fmt.Errorf("locationsLocation cannot load %T as %q", retrieved, name) + } + + o.R.CurrentLocationLocationsPackages = rels + + for _, rel := range rels { + if rel != nil { + rel.R.CurrentLocationLocationsLocation = o + } + } + return nil + case "PointerFileLocationLocationsPackages": + rels, ok := retrieved.(LocationsPackageSlice) + if !ok { + return fmt.Errorf("locationsLocation cannot load %T as %q", retrieved, name) + } + + o.R.PointerFileLocationLocationsPackages = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PointerFileLocationLocationsLocation = o + } + } + return nil + default: + return fmt.Errorf("locationsLocation has no relationship %q", name) + } +} + +type locationsLocationPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsLocationPreloader() locationsLocationPreloader { + return locationsLocationPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsLocations, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsLocationThenLoader[Q orm.Loadable] struct { + FromLocationLocationsLocationReplicators func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ToLocationLocationsLocationReplicators func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + LocationLocationsLocationpipelines func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + CurrentLocationLocationsPackages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PointerFileLocationLocationsPackages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsLocationThenLoader[Q orm.Loadable]() locationsLocationThenLoader[Q] { + type FromLocationLocationsLocationReplicatorsLoadInterface interface { + LoadFromLocationLocationsLocationReplicators(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ToLocationLocationsLocationReplicatorsLoadInterface interface { + LoadToLocationLocationsLocationReplicators(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type LocationLocationsLocationpipelinesLoadInterface interface { + LoadLocationLocationsLocationpipelines(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type CurrentLocationLocationsPackagesLoadInterface interface { + LoadCurrentLocationLocationsPackages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PointerFileLocationLocationsPackagesLoadInterface interface { + LoadPointerFileLocationLocationsPackages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsLocationThenLoader[Q]{ + FromLocationLocationsLocationReplicators: thenLoadBuilder[Q]( + "FromLocationLocationsLocationReplicators", + func(ctx context.Context, exec bob.Executor, retrieved FromLocationLocationsLocationReplicatorsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadFromLocationLocationsLocationReplicators(ctx, exec, mods...) + }, + ), + ToLocationLocationsLocationReplicators: thenLoadBuilder[Q]( + "ToLocationLocationsLocationReplicators", + func(ctx context.Context, exec bob.Executor, retrieved ToLocationLocationsLocationReplicatorsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadToLocationLocationsLocationReplicators(ctx, exec, mods...) + }, + ), + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + LocationLocationsLocationpipelines: thenLoadBuilder[Q]( + "LocationLocationsLocationpipelines", + func(ctx context.Context, exec bob.Executor, retrieved LocationLocationsLocationpipelinesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadLocationLocationsLocationpipelines(ctx, exec, mods...) + }, + ), + CurrentLocationLocationsPackages: thenLoadBuilder[Q]( + "CurrentLocationLocationsPackages", + func(ctx context.Context, exec bob.Executor, retrieved CurrentLocationLocationsPackagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadCurrentLocationLocationsPackages(ctx, exec, mods...) + }, + ), + PointerFileLocationLocationsPackages: thenLoadBuilder[Q]( + "PointerFileLocationLocationsPackages", + func(ctx context.Context, exec bob.Executor, retrieved PointerFileLocationLocationsPackagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPointerFileLocationLocationsPackages(ctx, exec, mods...) + }, + ), + } +} + +// LoadFromLocationLocationsLocationReplicators loads the locationsLocation's FromLocationLocationsLocationReplicators into the .R struct +func (o *LocationsLocation) LoadFromLocationLocationsLocationReplicators(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.FromLocationLocationsLocationReplicators = nil + + related, err := o.FromLocationLocationsLocationReplicators(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.FromLocationLocationsLocation = o + } + + o.R.FromLocationLocationsLocationReplicators = related + return nil +} + +// LoadFromLocationLocationsLocationReplicators loads the locationsLocation's FromLocationLocationsLocationReplicators into the .R struct +func (os LocationsLocationSlice) LoadFromLocationLocationsLocationReplicators(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocationReplicators, err := os.FromLocationLocationsLocationReplicators(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.FromLocationLocationsLocationReplicators = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocationReplicators { + + if !(o.ID == rel.FromLocationID) { + continue + } + + rel.R.FromLocationLocationsLocation = o + + o.R.FromLocationLocationsLocationReplicators = append(o.R.FromLocationLocationsLocationReplicators, rel) + } + } + + return nil +} + +// LoadToLocationLocationsLocationReplicators loads the locationsLocation's ToLocationLocationsLocationReplicators into the .R struct +func (o *LocationsLocation) LoadToLocationLocationsLocationReplicators(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ToLocationLocationsLocationReplicators = nil + + related, err := o.ToLocationLocationsLocationReplicators(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.ToLocationLocationsLocation = o + } + + o.R.ToLocationLocationsLocationReplicators = related + return nil +} + +// LoadToLocationLocationsLocationReplicators loads the locationsLocation's ToLocationLocationsLocationReplicators into the .R struct +func (os LocationsLocationSlice) LoadToLocationLocationsLocationReplicators(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocationReplicators, err := os.ToLocationLocationsLocationReplicators(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.ToLocationLocationsLocationReplicators = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocationReplicators { + + if !(o.ID == rel.ToLocationID) { + continue + } + + rel.R.ToLocationLocationsLocation = o + + o.R.ToLocationLocationsLocationReplicators = append(o.R.ToLocationLocationsLocationReplicators, rel) + } + } + + return nil +} + +// LoadSpaceLocationsSpace loads the locationsLocation's SpaceLocationsSpace into the .R struct +func (o *LocationsLocation) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsLocations = LocationsLocationSlice{o} + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsLocation's SpaceLocationsSpace into the .R struct +func (os LocationsLocationSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsLocations = append(rel.R.SpaceLocationsLocations, o) + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +// LoadLocationLocationsLocationpipelines loads the locationsLocation's LocationLocationsLocationpipelines into the .R struct +func (o *LocationsLocation) LoadLocationLocationsLocationpipelines(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.LocationLocationsLocationpipelines = nil + + related, err := o.LocationLocationsLocationpipelines(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.LocationLocationsLocation = o + } + + o.R.LocationLocationsLocationpipelines = related + return nil +} + +// LoadLocationLocationsLocationpipelines loads the locationsLocation's LocationLocationsLocationpipelines into the .R struct +func (os LocationsLocationSlice) LoadLocationLocationsLocationpipelines(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocationpipelines, err := os.LocationLocationsLocationpipelines(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.LocationLocationsLocationpipelines = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocationpipelines { + + if !(o.UUID == rel.LocationID) { + continue + } + + rel.R.LocationLocationsLocation = o + + o.R.LocationLocationsLocationpipelines = append(o.R.LocationLocationsLocationpipelines, rel) + } + } + + return nil +} + +// LoadCurrentLocationLocationsPackages loads the locationsLocation's CurrentLocationLocationsPackages into the .R struct +func (o *LocationsLocation) LoadCurrentLocationLocationsPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.CurrentLocationLocationsPackages = nil + + related, err := o.CurrentLocationLocationsPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.CurrentLocationLocationsLocation = o + } + + o.R.CurrentLocationLocationsPackages = related + return nil +} + +// LoadCurrentLocationLocationsPackages loads the locationsLocation's CurrentLocationLocationsPackages into the .R struct +func (os LocationsLocationSlice) LoadCurrentLocationLocationsPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.CurrentLocationLocationsPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.CurrentLocationLocationsPackages = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !(o.UUID == rel.CurrentLocationID) { + continue + } + + rel.R.CurrentLocationLocationsLocation = o + + o.R.CurrentLocationLocationsPackages = append(o.R.CurrentLocationLocationsPackages, rel) + } + } + + return nil +} + +// LoadPointerFileLocationLocationsPackages loads the locationsLocation's PointerFileLocationLocationsPackages into the .R struct +func (o *LocationsLocation) LoadPointerFileLocationLocationsPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PointerFileLocationLocationsPackages = nil + + related, err := o.PointerFileLocationLocationsPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PointerFileLocationLocationsLocation = o + } + + o.R.PointerFileLocationLocationsPackages = related + return nil +} + +// LoadPointerFileLocationLocationsPackages loads the locationsLocation's PointerFileLocationLocationsPackages into the .R struct +func (os LocationsLocationSlice) LoadPointerFileLocationLocationsPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.PointerFileLocationLocationsPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PointerFileLocationLocationsPackages = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !rel.PointerFileLocationID.IsValue() { + continue + } + if !(rel.PointerFileLocationID.IsValue() && o.UUID == rel.PointerFileLocationID.MustGet()) { + continue + } + + rel.R.PointerFileLocationLocationsLocation = o + + o.R.PointerFileLocationLocationsPackages = append(o.R.PointerFileLocationLocationsPackages, rel) + } + } + + return nil +} + +type locationsLocationJoins[Q dialect.Joinable] struct { + typ string + FromLocationLocationsLocationReplicators modAs[Q, locationsLocationReplicatorColumns] + ToLocationLocationsLocationReplicators modAs[Q, locationsLocationReplicatorColumns] + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] + LocationLocationsLocationpipelines modAs[Q, locationsLocationpipelineColumns] + CurrentLocationLocationsPackages modAs[Q, locationsPackageColumns] + PointerFileLocationLocationsPackages modAs[Q, locationsPackageColumns] +} + +func (j locationsLocationJoins[Q]) aliasedAs(alias string) locationsLocationJoins[Q] { + return buildLocationsLocationJoins[Q](buildLocationsLocationColumns(alias), j.typ) +} + +func buildLocationsLocationJoins[Q dialect.Joinable](cols locationsLocationColumns, typ string) locationsLocationJoins[Q] { + return locationsLocationJoins[Q]{ + typ: typ, + FromLocationLocationsLocationReplicators: modAs[Q, locationsLocationReplicatorColumns]{ + c: LocationsLocationReplicators.Columns, + f: func(to locationsLocationReplicatorColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocationReplicators.Name().As(to.Alias())).On( + to.FromLocationID.EQ(cols.ID), + )) + } + + return mods + }, + }, + ToLocationLocationsLocationReplicators: modAs[Q, locationsLocationReplicatorColumns]{ + c: LocationsLocationReplicators.Columns, + f: func(to locationsLocationReplicatorColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocationReplicators.Name().As(to.Alias())).On( + to.ToLocationID.EQ(cols.ID), + )) + } + + return mods + }, + }, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + LocationLocationsLocationpipelines: modAs[Q, locationsLocationpipelineColumns]{ + c: LocationsLocationpipelines.Columns, + f: func(to locationsLocationpipelineColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocationpipelines.Name().As(to.Alias())).On( + to.LocationID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + CurrentLocationLocationsPackages: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.CurrentLocationID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + PointerFileLocationLocationsPackages: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.PointerFileLocationID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_location_replicators.bob.go b/database/storage_service/models/locations_location_replicators.bob.go new file mode 100644 index 0000000..437a7f0 --- /dev/null +++ b/database/storage_service/models/locations_location_replicators.bob.go @@ -0,0 +1,787 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsLocationReplicator is an object representing the database table. +type LocationsLocationReplicator struct { + ID int32 `db:"id,pk,autoincr" ` + FromLocationID int32 `db:"from_location_id" ` + ToLocationID int32 `db:"to_location_id" ` + + R locationsLocationReplicatorR `db:"-" ` +} + +// LocationsLocationReplicatorSlice is an alias for a slice of pointers to LocationsLocationReplicator. +// This should almost always be used instead of []*LocationsLocationReplicator. +type LocationsLocationReplicatorSlice []*LocationsLocationReplicator + +// LocationsLocationReplicators contains methods to work with the locations_location_replicators table +var LocationsLocationReplicators = mysql.NewTablex[*LocationsLocationReplicator, LocationsLocationReplicatorSlice, *LocationsLocationReplicatorSetter]("locations_location_replicators", buildLocationsLocationReplicatorColumns("locations_location_replicators"), []string{"id"}, []string{"from_location_id", "to_location_id"}) + +// LocationsLocationReplicatorsQuery is a query on the locations_location_replicators table +type LocationsLocationReplicatorsQuery = *mysql.ViewQuery[*LocationsLocationReplicator, LocationsLocationReplicatorSlice] + +// locationsLocationReplicatorR is where relationships are stored. +type locationsLocationReplicatorR struct { + FromLocationLocationsLocation *LocationsLocation // locations_location_r_from_location_id_3b9a55f5_fk_locations + ToLocationLocationsLocation *LocationsLocation // locations_location_r_to_location_id_27be9af1_fk_locations +} + +func buildLocationsLocationReplicatorColumns(alias string) locationsLocationReplicatorColumns { + return locationsLocationReplicatorColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "from_location_id", "to_location_id", + ).WithParent("locations_location_replicators"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + FromLocationID: mysql.Quote(alias, "from_location_id"), + ToLocationID: mysql.Quote(alias, "to_location_id"), + } +} + +type locationsLocationReplicatorColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + FromLocationID mysql.Expression + ToLocationID mysql.Expression +} + +func (c locationsLocationReplicatorColumns) Alias() string { + return c.tableAlias +} + +func (locationsLocationReplicatorColumns) AliasedAs(alias string) locationsLocationReplicatorColumns { + return buildLocationsLocationReplicatorColumns(alias) +} + +// LocationsLocationReplicatorSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsLocationReplicatorSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + FromLocationID omit.Val[int32] `db:"from_location_id" ` + ToLocationID omit.Val[int32] `db:"to_location_id" ` +} + +func (s LocationsLocationReplicatorSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.FromLocationID.IsValue() { + vals = append(vals, "from_location_id") + } + if s.ToLocationID.IsValue() { + vals = append(vals, "to_location_id") + } + return vals +} + +func (s LocationsLocationReplicatorSetter) Overwrite(t *LocationsLocationReplicator) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.FromLocationID.IsValue() { + t.FromLocationID = s.FromLocationID.MustGet() + } + if s.ToLocationID.IsValue() { + t.ToLocationID = s.ToLocationID.MustGet() + } +} + +func (s *LocationsLocationReplicatorSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocationReplicators.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.FromLocationID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.FromLocationID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ToLocationID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ToLocationID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsLocationReplicatorSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_location_replicators")...) +} + +func (s LocationsLocationReplicatorSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.FromLocationID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "from_location_id")...), + mysql.Arg(s.FromLocationID), + }}) + } + + if s.ToLocationID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "to_location_id")...), + mysql.Arg(s.ToLocationID), + }}) + } + + return exprs +} + +// FindLocationsLocationReplicator retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsLocationReplicator(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsLocationReplicator, error) { + if len(cols) == 0 { + return LocationsLocationReplicators.Query( + sm.Where(LocationsLocationReplicators.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsLocationReplicators.Query( + sm.Where(LocationsLocationReplicators.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsLocationReplicators.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsLocationReplicatorExists checks the presence of a single record by primary key +func LocationsLocationReplicatorExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsLocationReplicators.Query( + sm.Where(LocationsLocationReplicators.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsLocationReplicator is retrieved from the database +func (o *LocationsLocationReplicator) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLocationReplicators.AfterSelectHooks.RunHooks(ctx, exec, LocationsLocationReplicatorSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsLocationReplicators.AfterInsertHooks.RunHooks(ctx, exec, LocationsLocationReplicatorSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsLocationReplicators.AfterUpdateHooks.RunHooks(ctx, exec, LocationsLocationReplicatorSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsLocationReplicators.AfterDeleteHooks.RunHooks(ctx, exec, LocationsLocationReplicatorSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsLocationReplicator +func (o *LocationsLocationReplicator) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsLocationReplicator) pkEQ() dialect.Expression { + return mysql.Quote("locations_location_replicators", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsLocationReplicator +func (o *LocationsLocationReplicator) Update(ctx context.Context, exec bob.Executor, s *LocationsLocationReplicatorSetter) error { + _, err := LocationsLocationReplicators.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsLocationReplicator record with an executor +func (o *LocationsLocationReplicator) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsLocationReplicators.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsLocationReplicator using the executor +func (o *LocationsLocationReplicator) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsLocationReplicators.Query( + sm.Where(LocationsLocationReplicators.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsLocationReplicatorSlice is retrieved from the database +func (o LocationsLocationReplicatorSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLocationReplicators.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsLocationReplicators.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsLocationReplicators.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsLocationReplicators.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsLocationReplicatorSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_location_replicators", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsLocationReplicatorSlice) copyMatchingRows(from ...*LocationsLocationReplicator) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsLocationReplicatorSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocationReplicators.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLocationReplicator: + o.copyMatchingRows(retrieved) + case []*LocationsLocationReplicator: + o.copyMatchingRows(retrieved...) + case LocationsLocationReplicatorSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLocationReplicator or a slice of LocationsLocationReplicator + // then run the AfterUpdateHooks on the slice + _, err = LocationsLocationReplicators.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsLocationReplicatorSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocationReplicators.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLocationReplicator: + o.copyMatchingRows(retrieved) + case []*LocationsLocationReplicator: + o.copyMatchingRows(retrieved...) + case LocationsLocationReplicatorSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLocationReplicator or a slice of LocationsLocationReplicator + // then run the AfterDeleteHooks on the slice + _, err = LocationsLocationReplicators.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsLocationReplicatorSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsLocationReplicatorSetter) error { + _, err := LocationsLocationReplicators.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsLocationReplicatorSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsLocationReplicators.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsLocationReplicatorSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsLocationReplicators.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// FromLocationLocationsLocation starts a query for related objects on locations_location +func (o *LocationsLocationReplicator) FromLocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + return LocationsLocations.Query(append(mods, + sm.Where(LocationsLocations.Columns.ID.EQ(mysql.Arg(o.FromLocationID))), + )...) +} + +func (os LocationsLocationReplicatorSlice) FromLocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.FromLocationID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocations.Query(append(mods, + sm.Where(mysql.Group(LocationsLocations.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// ToLocationLocationsLocation starts a query for related objects on locations_location +func (o *LocationsLocationReplicator) ToLocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + return LocationsLocations.Query(append(mods, + sm.Where(LocationsLocations.Columns.ID.EQ(mysql.Arg(o.ToLocationID))), + )...) +} + +func (os LocationsLocationReplicatorSlice) ToLocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ToLocationID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocations.Query(append(mods, + sm.Where(mysql.Group(LocationsLocations.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsLocationReplicatorFromLocationLocationsLocation0(ctx context.Context, exec bob.Executor, count int, locationsLocationReplicator0 *LocationsLocationReplicator, locationsLocation1 *LocationsLocation) (*LocationsLocationReplicator, error) { + setter := &LocationsLocationReplicatorSetter{ + FromLocationID: omit.From(locationsLocation1.ID), + } + + err := locationsLocationReplicator0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationReplicatorFromLocationLocationsLocation0: %w", err) + } + + return locationsLocationReplicator0, nil +} + +func (locationsLocationReplicator0 *LocationsLocationReplicator) InsertFromLocationLocationsLocation(ctx context.Context, exec bob.Executor, related *LocationsLocationSetter) error { + var err error + + locationsLocation1, err := LocationsLocations.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsLocationReplicatorFromLocationLocationsLocation0(ctx, exec, 1, locationsLocationReplicator0, locationsLocation1) + if err != nil { + return err + } + + locationsLocationReplicator0.R.FromLocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.FromLocationLocationsLocationReplicators = append(locationsLocation1.R.FromLocationLocationsLocationReplicators, locationsLocationReplicator0) + + return nil +} + +func (locationsLocationReplicator0 *LocationsLocationReplicator) AttachFromLocationLocationsLocation(ctx context.Context, exec bob.Executor, locationsLocation1 *LocationsLocation) error { + var err error + + _, err = attachLocationsLocationReplicatorFromLocationLocationsLocation0(ctx, exec, 1, locationsLocationReplicator0, locationsLocation1) + if err != nil { + return err + } + + locationsLocationReplicator0.R.FromLocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.FromLocationLocationsLocationReplicators = append(locationsLocation1.R.FromLocationLocationsLocationReplicators, locationsLocationReplicator0) + + return nil +} + +func attachLocationsLocationReplicatorToLocationLocationsLocation0(ctx context.Context, exec bob.Executor, count int, locationsLocationReplicator0 *LocationsLocationReplicator, locationsLocation1 *LocationsLocation) (*LocationsLocationReplicator, error) { + setter := &LocationsLocationReplicatorSetter{ + ToLocationID: omit.From(locationsLocation1.ID), + } + + err := locationsLocationReplicator0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationReplicatorToLocationLocationsLocation0: %w", err) + } + + return locationsLocationReplicator0, nil +} + +func (locationsLocationReplicator0 *LocationsLocationReplicator) InsertToLocationLocationsLocation(ctx context.Context, exec bob.Executor, related *LocationsLocationSetter) error { + var err error + + locationsLocation1, err := LocationsLocations.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsLocationReplicatorToLocationLocationsLocation0(ctx, exec, 1, locationsLocationReplicator0, locationsLocation1) + if err != nil { + return err + } + + locationsLocationReplicator0.R.ToLocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.ToLocationLocationsLocationReplicators = append(locationsLocation1.R.ToLocationLocationsLocationReplicators, locationsLocationReplicator0) + + return nil +} + +func (locationsLocationReplicator0 *LocationsLocationReplicator) AttachToLocationLocationsLocation(ctx context.Context, exec bob.Executor, locationsLocation1 *LocationsLocation) error { + var err error + + _, err = attachLocationsLocationReplicatorToLocationLocationsLocation0(ctx, exec, 1, locationsLocationReplicator0, locationsLocation1) + if err != nil { + return err + } + + locationsLocationReplicator0.R.ToLocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.ToLocationLocationsLocationReplicators = append(locationsLocation1.R.ToLocationLocationsLocationReplicators, locationsLocationReplicator0) + + return nil +} + +type locationsLocationReplicatorWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + FromLocationID mysql.WhereMod[Q, int32] + ToLocationID mysql.WhereMod[Q, int32] +} + +func (locationsLocationReplicatorWhere[Q]) AliasedAs(alias string) locationsLocationReplicatorWhere[Q] { + return buildLocationsLocationReplicatorWhere[Q](buildLocationsLocationReplicatorColumns(alias)) +} + +func buildLocationsLocationReplicatorWhere[Q mysql.Filterable](cols locationsLocationReplicatorColumns) locationsLocationReplicatorWhere[Q] { + return locationsLocationReplicatorWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + FromLocationID: mysql.Where[Q, int32](cols.FromLocationID), + ToLocationID: mysql.Where[Q, int32](cols.ToLocationID), + } +} + +func (o *LocationsLocationReplicator) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "FromLocationLocationsLocation": + rel, ok := retrieved.(*LocationsLocation) + if !ok { + return fmt.Errorf("locationsLocationReplicator cannot load %T as %q", retrieved, name) + } + + o.R.FromLocationLocationsLocation = rel + + if rel != nil { + rel.R.FromLocationLocationsLocationReplicators = LocationsLocationReplicatorSlice{o} + } + return nil + case "ToLocationLocationsLocation": + rel, ok := retrieved.(*LocationsLocation) + if !ok { + return fmt.Errorf("locationsLocationReplicator cannot load %T as %q", retrieved, name) + } + + o.R.ToLocationLocationsLocation = rel + + if rel != nil { + rel.R.ToLocationLocationsLocationReplicators = LocationsLocationReplicatorSlice{o} + } + return nil + default: + return fmt.Errorf("locationsLocationReplicator has no relationship %q", name) + } +} + +type locationsLocationReplicatorPreloader struct { + FromLocationLocationsLocation func(...mysql.PreloadOption) mysql.Preloader + ToLocationLocationsLocation func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsLocationReplicatorPreloader() locationsLocationReplicatorPreloader { + return locationsLocationReplicatorPreloader{ + FromLocationLocationsLocation: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsLocation, LocationsLocationSlice](mysql.PreloadRel{ + Name: "FromLocationLocationsLocation", + Sides: []mysql.PreloadSide{ + { + From: LocationsLocationReplicators, + To: LocationsLocations, + FromColumns: []string{"from_location_id"}, + ToColumns: []string{"id"}, + }, + }, + }, LocationsLocations.Columns.Names(), opts...) + }, + ToLocationLocationsLocation: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsLocation, LocationsLocationSlice](mysql.PreloadRel{ + Name: "ToLocationLocationsLocation", + Sides: []mysql.PreloadSide{ + { + From: LocationsLocationReplicators, + To: LocationsLocations, + FromColumns: []string{"to_location_id"}, + ToColumns: []string{"id"}, + }, + }, + }, LocationsLocations.Columns.Names(), opts...) + }, + } +} + +type locationsLocationReplicatorThenLoader[Q orm.Loadable] struct { + FromLocationLocationsLocation func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ToLocationLocationsLocation func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsLocationReplicatorThenLoader[Q orm.Loadable]() locationsLocationReplicatorThenLoader[Q] { + type FromLocationLocationsLocationLoadInterface interface { + LoadFromLocationLocationsLocation(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ToLocationLocationsLocationLoadInterface interface { + LoadToLocationLocationsLocation(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsLocationReplicatorThenLoader[Q]{ + FromLocationLocationsLocation: thenLoadBuilder[Q]( + "FromLocationLocationsLocation", + func(ctx context.Context, exec bob.Executor, retrieved FromLocationLocationsLocationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadFromLocationLocationsLocation(ctx, exec, mods...) + }, + ), + ToLocationLocationsLocation: thenLoadBuilder[Q]( + "ToLocationLocationsLocation", + func(ctx context.Context, exec bob.Executor, retrieved ToLocationLocationsLocationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadToLocationLocationsLocation(ctx, exec, mods...) + }, + ), + } +} + +// LoadFromLocationLocationsLocation loads the locationsLocationReplicator's FromLocationLocationsLocation into the .R struct +func (o *LocationsLocationReplicator) LoadFromLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.FromLocationLocationsLocation = nil + + related, err := o.FromLocationLocationsLocation(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.FromLocationLocationsLocationReplicators = LocationsLocationReplicatorSlice{o} + + o.R.FromLocationLocationsLocation = related + return nil +} + +// LoadFromLocationLocationsLocation loads the locationsLocationReplicator's FromLocationLocationsLocation into the .R struct +func (os LocationsLocationReplicatorSlice) LoadFromLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocations, err := os.FromLocationLocationsLocation(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocations { + + if !(o.FromLocationID == rel.ID) { + continue + } + + rel.R.FromLocationLocationsLocationReplicators = append(rel.R.FromLocationLocationsLocationReplicators, o) + + o.R.FromLocationLocationsLocation = rel + break + } + } + + return nil +} + +// LoadToLocationLocationsLocation loads the locationsLocationReplicator's ToLocationLocationsLocation into the .R struct +func (o *LocationsLocationReplicator) LoadToLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ToLocationLocationsLocation = nil + + related, err := o.ToLocationLocationsLocation(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.ToLocationLocationsLocationReplicators = LocationsLocationReplicatorSlice{o} + + o.R.ToLocationLocationsLocation = related + return nil +} + +// LoadToLocationLocationsLocation loads the locationsLocationReplicator's ToLocationLocationsLocation into the .R struct +func (os LocationsLocationReplicatorSlice) LoadToLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocations, err := os.ToLocationLocationsLocation(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocations { + + if !(o.ToLocationID == rel.ID) { + continue + } + + rel.R.ToLocationLocationsLocationReplicators = append(rel.R.ToLocationLocationsLocationReplicators, o) + + o.R.ToLocationLocationsLocation = rel + break + } + } + + return nil +} + +type locationsLocationReplicatorJoins[Q dialect.Joinable] struct { + typ string + FromLocationLocationsLocation modAs[Q, locationsLocationColumns] + ToLocationLocationsLocation modAs[Q, locationsLocationColumns] +} + +func (j locationsLocationReplicatorJoins[Q]) aliasedAs(alias string) locationsLocationReplicatorJoins[Q] { + return buildLocationsLocationReplicatorJoins[Q](buildLocationsLocationReplicatorColumns(alias), j.typ) +} + +func buildLocationsLocationReplicatorJoins[Q dialect.Joinable](cols locationsLocationReplicatorColumns, typ string) locationsLocationReplicatorJoins[Q] { + return locationsLocationReplicatorJoins[Q]{ + typ: typ, + FromLocationLocationsLocation: modAs[Q, locationsLocationColumns]{ + c: LocationsLocations.Columns, + f: func(to locationsLocationColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocations.Name().As(to.Alias())).On( + to.ID.EQ(cols.FromLocationID), + )) + } + + return mods + }, + }, + ToLocationLocationsLocation: modAs[Q, locationsLocationColumns]{ + c: LocationsLocations.Columns, + f: func(to locationsLocationColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocations.Name().As(to.Alias())).On( + to.ID.EQ(cols.ToLocationID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_locationpipeline.bob.go b/database/storage_service/models/locations_locationpipeline.bob.go new file mode 100644 index 0000000..c64e2c2 --- /dev/null +++ b/database/storage_service/models/locations_locationpipeline.bob.go @@ -0,0 +1,787 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsLocationpipeline is an object representing the database table. +type LocationsLocationpipeline struct { + ID int32 `db:"id,pk,autoincr" ` + LocationID string `db:"location_id" ` + PipelineID string `db:"pipeline_id" ` + + R locationsLocationpipelineR `db:"-" ` +} + +// LocationsLocationpipelineSlice is an alias for a slice of pointers to LocationsLocationpipeline. +// This should almost always be used instead of []*LocationsLocationpipeline. +type LocationsLocationpipelineSlice []*LocationsLocationpipeline + +// LocationsLocationpipelines contains methods to work with the locations_locationpipeline table +var LocationsLocationpipelines = mysql.NewTablex[*LocationsLocationpipeline, LocationsLocationpipelineSlice, *LocationsLocationpipelineSetter]("locations_locationpipeline", buildLocationsLocationpipelineColumns("locations_locationpipeline"), []string{"id"}) + +// LocationsLocationpipelinesQuery is a query on the locations_locationpipeline table +type LocationsLocationpipelinesQuery = *mysql.ViewQuery[*LocationsLocationpipeline, LocationsLocationpipelineSlice] + +// locationsLocationpipelineR is where relationships are stored. +type locationsLocationpipelineR struct { + LocationLocationsLocation *LocationsLocation // locations_locationpi_location_id_1bff2f57_fk_locations + PipelineLocationsPipeline *LocationsPipeline // locations_locationpi_pipeline_id_2ad721b4_fk_locations +} + +func buildLocationsLocationpipelineColumns(alias string) locationsLocationpipelineColumns { + return locationsLocationpipelineColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "location_id", "pipeline_id", + ).WithParent("locations_locationpipeline"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + LocationID: mysql.Quote(alias, "location_id"), + PipelineID: mysql.Quote(alias, "pipeline_id"), + } +} + +type locationsLocationpipelineColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + LocationID mysql.Expression + PipelineID mysql.Expression +} + +func (c locationsLocationpipelineColumns) Alias() string { + return c.tableAlias +} + +func (locationsLocationpipelineColumns) AliasedAs(alias string) locationsLocationpipelineColumns { + return buildLocationsLocationpipelineColumns(alias) +} + +// LocationsLocationpipelineSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsLocationpipelineSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + LocationID omit.Val[string] `db:"location_id" ` + PipelineID omit.Val[string] `db:"pipeline_id" ` +} + +func (s LocationsLocationpipelineSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.LocationID.IsValue() { + vals = append(vals, "location_id") + } + if s.PipelineID.IsValue() { + vals = append(vals, "pipeline_id") + } + return vals +} + +func (s LocationsLocationpipelineSetter) Overwrite(t *LocationsLocationpipeline) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.LocationID.IsValue() { + t.LocationID = s.LocationID.MustGet() + } + if s.PipelineID.IsValue() { + t.PipelineID = s.PipelineID.MustGet() + } +} + +func (s *LocationsLocationpipelineSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocationpipelines.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.LocationID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.LocationID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.PipelineID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PipelineID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsLocationpipelineSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_locationpipeline")...) +} + +func (s LocationsLocationpipelineSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.LocationID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "location_id")...), + mysql.Arg(s.LocationID), + }}) + } + + if s.PipelineID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "pipeline_id")...), + mysql.Arg(s.PipelineID), + }}) + } + + return exprs +} + +// FindLocationsLocationpipeline retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsLocationpipeline(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsLocationpipeline, error) { + if len(cols) == 0 { + return LocationsLocationpipelines.Query( + sm.Where(LocationsLocationpipelines.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsLocationpipelines.Query( + sm.Where(LocationsLocationpipelines.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsLocationpipelines.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsLocationpipelineExists checks the presence of a single record by primary key +func LocationsLocationpipelineExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsLocationpipelines.Query( + sm.Where(LocationsLocationpipelines.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsLocationpipeline is retrieved from the database +func (o *LocationsLocationpipeline) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLocationpipelines.AfterSelectHooks.RunHooks(ctx, exec, LocationsLocationpipelineSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsLocationpipelines.AfterInsertHooks.RunHooks(ctx, exec, LocationsLocationpipelineSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsLocationpipelines.AfterUpdateHooks.RunHooks(ctx, exec, LocationsLocationpipelineSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsLocationpipelines.AfterDeleteHooks.RunHooks(ctx, exec, LocationsLocationpipelineSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsLocationpipeline +func (o *LocationsLocationpipeline) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsLocationpipeline) pkEQ() dialect.Expression { + return mysql.Quote("locations_locationpipeline", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsLocationpipeline +func (o *LocationsLocationpipeline) Update(ctx context.Context, exec bob.Executor, s *LocationsLocationpipelineSetter) error { + _, err := LocationsLocationpipelines.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsLocationpipeline record with an executor +func (o *LocationsLocationpipeline) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsLocationpipelines.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsLocationpipeline using the executor +func (o *LocationsLocationpipeline) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsLocationpipelines.Query( + sm.Where(LocationsLocationpipelines.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsLocationpipelineSlice is retrieved from the database +func (o LocationsLocationpipelineSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLocationpipelines.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsLocationpipelines.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsLocationpipelines.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsLocationpipelines.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsLocationpipelineSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_locationpipeline", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsLocationpipelineSlice) copyMatchingRows(from ...*LocationsLocationpipeline) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsLocationpipelineSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocationpipelines.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLocationpipeline: + o.copyMatchingRows(retrieved) + case []*LocationsLocationpipeline: + o.copyMatchingRows(retrieved...) + case LocationsLocationpipelineSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLocationpipeline or a slice of LocationsLocationpipeline + // then run the AfterUpdateHooks on the slice + _, err = LocationsLocationpipelines.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsLocationpipelineSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLocationpipelines.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLocationpipeline: + o.copyMatchingRows(retrieved) + case []*LocationsLocationpipeline: + o.copyMatchingRows(retrieved...) + case LocationsLocationpipelineSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLocationpipeline or a slice of LocationsLocationpipeline + // then run the AfterDeleteHooks on the slice + _, err = LocationsLocationpipelines.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsLocationpipelineSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsLocationpipelineSetter) error { + _, err := LocationsLocationpipelines.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsLocationpipelineSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsLocationpipelines.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsLocationpipelineSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsLocationpipelines.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// LocationLocationsLocation starts a query for related objects on locations_location +func (o *LocationsLocationpipeline) LocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + return LocationsLocations.Query(append(mods, + sm.Where(LocationsLocations.Columns.UUID.EQ(mysql.Arg(o.LocationID))), + )...) +} + +func (os LocationsLocationpipelineSlice) LocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.LocationID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocations.Query(append(mods, + sm.Where(mysql.Group(LocationsLocations.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +// PipelineLocationsPipeline starts a query for related objects on locations_pipeline +func (o *LocationsLocationpipeline) PipelineLocationsPipeline(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPipelinesQuery { + return LocationsPipelines.Query(append(mods, + sm.Where(LocationsPipelines.Columns.UUID.EQ(mysql.Arg(o.PipelineID))), + )...) +} + +func (os LocationsLocationpipelineSlice) PipelineLocationsPipeline(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPipelinesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PipelineID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPipelines.Query(append(mods, + sm.Where(mysql.Group(LocationsPipelines.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsLocationpipelineLocationLocationsLocation0(ctx context.Context, exec bob.Executor, count int, locationsLocationpipeline0 *LocationsLocationpipeline, locationsLocation1 *LocationsLocation) (*LocationsLocationpipeline, error) { + setter := &LocationsLocationpipelineSetter{ + LocationID: omit.From(locationsLocation1.UUID), + } + + err := locationsLocationpipeline0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationpipelineLocationLocationsLocation0: %w", err) + } + + return locationsLocationpipeline0, nil +} + +func (locationsLocationpipeline0 *LocationsLocationpipeline) InsertLocationLocationsLocation(ctx context.Context, exec bob.Executor, related *LocationsLocationSetter) error { + var err error + + locationsLocation1, err := LocationsLocations.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsLocationpipelineLocationLocationsLocation0(ctx, exec, 1, locationsLocationpipeline0, locationsLocation1) + if err != nil { + return err + } + + locationsLocationpipeline0.R.LocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.LocationLocationsLocationpipelines = append(locationsLocation1.R.LocationLocationsLocationpipelines, locationsLocationpipeline0) + + return nil +} + +func (locationsLocationpipeline0 *LocationsLocationpipeline) AttachLocationLocationsLocation(ctx context.Context, exec bob.Executor, locationsLocation1 *LocationsLocation) error { + var err error + + _, err = attachLocationsLocationpipelineLocationLocationsLocation0(ctx, exec, 1, locationsLocationpipeline0, locationsLocation1) + if err != nil { + return err + } + + locationsLocationpipeline0.R.LocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.LocationLocationsLocationpipelines = append(locationsLocation1.R.LocationLocationsLocationpipelines, locationsLocationpipeline0) + + return nil +} + +func attachLocationsLocationpipelinePipelineLocationsPipeline0(ctx context.Context, exec bob.Executor, count int, locationsLocationpipeline0 *LocationsLocationpipeline, locationsPipeline1 *LocationsPipeline) (*LocationsLocationpipeline, error) { + setter := &LocationsLocationpipelineSetter{ + PipelineID: omit.From(locationsPipeline1.UUID), + } + + err := locationsLocationpipeline0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLocationpipelinePipelineLocationsPipeline0: %w", err) + } + + return locationsLocationpipeline0, nil +} + +func (locationsLocationpipeline0 *LocationsLocationpipeline) InsertPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, related *LocationsPipelineSetter) error { + var err error + + locationsPipeline1, err := LocationsPipelines.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsLocationpipelinePipelineLocationsPipeline0(ctx, exec, 1, locationsLocationpipeline0, locationsPipeline1) + if err != nil { + return err + } + + locationsLocationpipeline0.R.PipelineLocationsPipeline = locationsPipeline1 + + locationsPipeline1.R.PipelineLocationsLocationpipelines = append(locationsPipeline1.R.PipelineLocationsLocationpipelines, locationsLocationpipeline0) + + return nil +} + +func (locationsLocationpipeline0 *LocationsLocationpipeline) AttachPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, locationsPipeline1 *LocationsPipeline) error { + var err error + + _, err = attachLocationsLocationpipelinePipelineLocationsPipeline0(ctx, exec, 1, locationsLocationpipeline0, locationsPipeline1) + if err != nil { + return err + } + + locationsLocationpipeline0.R.PipelineLocationsPipeline = locationsPipeline1 + + locationsPipeline1.R.PipelineLocationsLocationpipelines = append(locationsPipeline1.R.PipelineLocationsLocationpipelines, locationsLocationpipeline0) + + return nil +} + +type locationsLocationpipelineWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + LocationID mysql.WhereMod[Q, string] + PipelineID mysql.WhereMod[Q, string] +} + +func (locationsLocationpipelineWhere[Q]) AliasedAs(alias string) locationsLocationpipelineWhere[Q] { + return buildLocationsLocationpipelineWhere[Q](buildLocationsLocationpipelineColumns(alias)) +} + +func buildLocationsLocationpipelineWhere[Q mysql.Filterable](cols locationsLocationpipelineColumns) locationsLocationpipelineWhere[Q] { + return locationsLocationpipelineWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + LocationID: mysql.Where[Q, string](cols.LocationID), + PipelineID: mysql.Where[Q, string](cols.PipelineID), + } +} + +func (o *LocationsLocationpipeline) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "LocationLocationsLocation": + rel, ok := retrieved.(*LocationsLocation) + if !ok { + return fmt.Errorf("locationsLocationpipeline cannot load %T as %q", retrieved, name) + } + + o.R.LocationLocationsLocation = rel + + if rel != nil { + rel.R.LocationLocationsLocationpipelines = LocationsLocationpipelineSlice{o} + } + return nil + case "PipelineLocationsPipeline": + rel, ok := retrieved.(*LocationsPipeline) + if !ok { + return fmt.Errorf("locationsLocationpipeline cannot load %T as %q", retrieved, name) + } + + o.R.PipelineLocationsPipeline = rel + + if rel != nil { + rel.R.PipelineLocationsLocationpipelines = LocationsLocationpipelineSlice{o} + } + return nil + default: + return fmt.Errorf("locationsLocationpipeline has no relationship %q", name) + } +} + +type locationsLocationpipelinePreloader struct { + LocationLocationsLocation func(...mysql.PreloadOption) mysql.Preloader + PipelineLocationsPipeline func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsLocationpipelinePreloader() locationsLocationpipelinePreloader { + return locationsLocationpipelinePreloader{ + LocationLocationsLocation: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsLocation, LocationsLocationSlice](mysql.PreloadRel{ + Name: "LocationLocationsLocation", + Sides: []mysql.PreloadSide{ + { + From: LocationsLocationpipelines, + To: LocationsLocations, + FromColumns: []string{"location_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsLocations.Columns.Names(), opts...) + }, + PipelineLocationsPipeline: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPipeline, LocationsPipelineSlice](mysql.PreloadRel{ + Name: "PipelineLocationsPipeline", + Sides: []mysql.PreloadSide{ + { + From: LocationsLocationpipelines, + To: LocationsPipelines, + FromColumns: []string{"pipeline_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsPipelines.Columns.Names(), opts...) + }, + } +} + +type locationsLocationpipelineThenLoader[Q orm.Loadable] struct { + LocationLocationsLocation func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PipelineLocationsPipeline func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsLocationpipelineThenLoader[Q orm.Loadable]() locationsLocationpipelineThenLoader[Q] { + type LocationLocationsLocationLoadInterface interface { + LoadLocationLocationsLocation(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PipelineLocationsPipelineLoadInterface interface { + LoadPipelineLocationsPipeline(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsLocationpipelineThenLoader[Q]{ + LocationLocationsLocation: thenLoadBuilder[Q]( + "LocationLocationsLocation", + func(ctx context.Context, exec bob.Executor, retrieved LocationLocationsLocationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadLocationLocationsLocation(ctx, exec, mods...) + }, + ), + PipelineLocationsPipeline: thenLoadBuilder[Q]( + "PipelineLocationsPipeline", + func(ctx context.Context, exec bob.Executor, retrieved PipelineLocationsPipelineLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPipelineLocationsPipeline(ctx, exec, mods...) + }, + ), + } +} + +// LoadLocationLocationsLocation loads the locationsLocationpipeline's LocationLocationsLocation into the .R struct +func (o *LocationsLocationpipeline) LoadLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.LocationLocationsLocation = nil + + related, err := o.LocationLocationsLocation(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.LocationLocationsLocationpipelines = LocationsLocationpipelineSlice{o} + + o.R.LocationLocationsLocation = related + return nil +} + +// LoadLocationLocationsLocation loads the locationsLocationpipeline's LocationLocationsLocation into the .R struct +func (os LocationsLocationpipelineSlice) LoadLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocations, err := os.LocationLocationsLocation(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocations { + + if !(o.LocationID == rel.UUID) { + continue + } + + rel.R.LocationLocationsLocationpipelines = append(rel.R.LocationLocationsLocationpipelines, o) + + o.R.LocationLocationsLocation = rel + break + } + } + + return nil +} + +// LoadPipelineLocationsPipeline loads the locationsLocationpipeline's PipelineLocationsPipeline into the .R struct +func (o *LocationsLocationpipeline) LoadPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PipelineLocationsPipeline = nil + + related, err := o.PipelineLocationsPipeline(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PipelineLocationsLocationpipelines = LocationsLocationpipelineSlice{o} + + o.R.PipelineLocationsPipeline = related + return nil +} + +// LoadPipelineLocationsPipeline loads the locationsLocationpipeline's PipelineLocationsPipeline into the .R struct +func (os LocationsLocationpipelineSlice) LoadPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPipelines, err := os.PipelineLocationsPipeline(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPipelines { + + if !(o.PipelineID == rel.UUID) { + continue + } + + rel.R.PipelineLocationsLocationpipelines = append(rel.R.PipelineLocationsLocationpipelines, o) + + o.R.PipelineLocationsPipeline = rel + break + } + } + + return nil +} + +type locationsLocationpipelineJoins[Q dialect.Joinable] struct { + typ string + LocationLocationsLocation modAs[Q, locationsLocationColumns] + PipelineLocationsPipeline modAs[Q, locationsPipelineColumns] +} + +func (j locationsLocationpipelineJoins[Q]) aliasedAs(alias string) locationsLocationpipelineJoins[Q] { + return buildLocationsLocationpipelineJoins[Q](buildLocationsLocationpipelineColumns(alias), j.typ) +} + +func buildLocationsLocationpipelineJoins[Q dialect.Joinable](cols locationsLocationpipelineColumns, typ string) locationsLocationpipelineJoins[Q] { + return locationsLocationpipelineJoins[Q]{ + typ: typ, + LocationLocationsLocation: modAs[Q, locationsLocationColumns]{ + c: LocationsLocations.Columns, + f: func(to locationsLocationColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocations.Name().As(to.Alias())).On( + to.UUID.EQ(cols.LocationID), + )) + } + + return mods + }, + }, + PipelineLocationsPipeline: modAs[Q, locationsPipelineColumns]{ + c: LocationsPipelines.Columns, + f: func(to locationsPipelineColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPipelines.Name().As(to.Alias())).On( + to.UUID.EQ(cols.PipelineID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_lockssomatic.bob.go b/database/storage_service/models/locations_lockssomatic.bob.go new file mode 100644 index 0000000..11968c0 --- /dev/null +++ b/database/storage_service/models/locations_lockssomatic.bob.go @@ -0,0 +1,762 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsLockssomatic is an object representing the database table. +type LocationsLockssomatic struct { + ID int32 `db:"id,pk,autoincr" ` + AuSize null.Val[int64] `db:"au_size" ` + SDIri string `db:"sd_iri" ` + CollectionIri null.Val[string] `db:"collection_iri" ` + ContentProviderID string `db:"content_provider_id" ` + ExternalDomain string `db:"external_domain" ` + ChecksumType null.Val[string] `db:"checksum_type" ` + KeepLocal bool `db:"keep_local" ` + SpaceID string `db:"space_id" ` + + R locationsLockssomaticR `db:"-" ` +} + +// LocationsLockssomaticSlice is an alias for a slice of pointers to LocationsLockssomatic. +// This should almost always be used instead of []*LocationsLockssomatic. +type LocationsLockssomaticSlice []*LocationsLockssomatic + +// LocationsLockssomatics contains methods to work with the locations_lockssomatic table +var LocationsLockssomatics = mysql.NewTablex[*LocationsLockssomatic, LocationsLockssomaticSlice, *LocationsLockssomaticSetter]("locations_lockssomatic", buildLocationsLockssomaticColumns("locations_lockssomatic"), []string{"id"}, []string{"space_id"}) + +// LocationsLockssomaticsQuery is a query on the locations_lockssomatic table +type LocationsLockssomaticsQuery = *mysql.ViewQuery[*LocationsLockssomatic, LocationsLockssomaticSlice] + +// locationsLockssomaticR is where relationships are stored. +type locationsLockssomaticR struct { + SpaceLocationsSpace *LocationsSpace // locations_lockssomatic_space_id_cc6a3cd6_fk_locations_space_uuid +} + +func buildLocationsLockssomaticColumns(alias string) locationsLockssomaticColumns { + return locationsLockssomaticColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "au_size", "sd_iri", "collection_iri", "content_provider_id", "external_domain", "checksum_type", "keep_local", "space_id", + ).WithParent("locations_lockssomatic"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + AuSize: mysql.Quote(alias, "au_size"), + SDIri: mysql.Quote(alias, "sd_iri"), + CollectionIri: mysql.Quote(alias, "collection_iri"), + ContentProviderID: mysql.Quote(alias, "content_provider_id"), + ExternalDomain: mysql.Quote(alias, "external_domain"), + ChecksumType: mysql.Quote(alias, "checksum_type"), + KeepLocal: mysql.Quote(alias, "keep_local"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsLockssomaticColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + AuSize mysql.Expression + SDIri mysql.Expression + CollectionIri mysql.Expression + ContentProviderID mysql.Expression + ExternalDomain mysql.Expression + ChecksumType mysql.Expression + KeepLocal mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsLockssomaticColumns) Alias() string { + return c.tableAlias +} + +func (locationsLockssomaticColumns) AliasedAs(alias string) locationsLockssomaticColumns { + return buildLocationsLockssomaticColumns(alias) +} + +// LocationsLockssomaticSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsLockssomaticSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + AuSize omitnull.Val[int64] `db:"au_size" ` + SDIri omit.Val[string] `db:"sd_iri" ` + CollectionIri omitnull.Val[string] `db:"collection_iri" ` + ContentProviderID omit.Val[string] `db:"content_provider_id" ` + ExternalDomain omit.Val[string] `db:"external_domain" ` + ChecksumType omitnull.Val[string] `db:"checksum_type" ` + KeepLocal omit.Val[bool] `db:"keep_local" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsLockssomaticSetter) SetColumns() []string { + vals := make([]string, 0, 9) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if !s.AuSize.IsUnset() { + vals = append(vals, "au_size") + } + if s.SDIri.IsValue() { + vals = append(vals, "sd_iri") + } + if !s.CollectionIri.IsUnset() { + vals = append(vals, "collection_iri") + } + if s.ContentProviderID.IsValue() { + vals = append(vals, "content_provider_id") + } + if s.ExternalDomain.IsValue() { + vals = append(vals, "external_domain") + } + if !s.ChecksumType.IsUnset() { + vals = append(vals, "checksum_type") + } + if s.KeepLocal.IsValue() { + vals = append(vals, "keep_local") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsLockssomaticSetter) Overwrite(t *LocationsLockssomatic) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if !s.AuSize.IsUnset() { + t.AuSize = s.AuSize.MustGetNull() + } + if s.SDIri.IsValue() { + t.SDIri = s.SDIri.MustGet() + } + if !s.CollectionIri.IsUnset() { + t.CollectionIri = s.CollectionIri.MustGetNull() + } + if s.ContentProviderID.IsValue() { + t.ContentProviderID = s.ContentProviderID.MustGet() + } + if s.ExternalDomain.IsValue() { + t.ExternalDomain = s.ExternalDomain.MustGet() + } + if !s.ChecksumType.IsUnset() { + t.ChecksumType = s.ChecksumType.MustGetNull() + } + if s.KeepLocal.IsValue() { + t.KeepLocal = s.KeepLocal.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsLockssomaticSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLockssomatics.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.AuSize.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AuSize.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SDIri.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SDIri.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.CollectionIri.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.CollectionIri.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ContentProviderID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ContentProviderID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ExternalDomain.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ExternalDomain.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.ChecksumType.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ChecksumType.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.KeepLocal.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.KeepLocal.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsLockssomaticSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_lockssomatic")...) +} + +func (s LocationsLockssomaticSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 9) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if !s.AuSize.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "au_size")...), + mysql.Arg(s.AuSize), + }}) + } + + if s.SDIri.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "sd_iri")...), + mysql.Arg(s.SDIri), + }}) + } + + if !s.CollectionIri.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "collection_iri")...), + mysql.Arg(s.CollectionIri), + }}) + } + + if s.ContentProviderID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "content_provider_id")...), + mysql.Arg(s.ContentProviderID), + }}) + } + + if s.ExternalDomain.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "external_domain")...), + mysql.Arg(s.ExternalDomain), + }}) + } + + if !s.ChecksumType.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "checksum_type")...), + mysql.Arg(s.ChecksumType), + }}) + } + + if s.KeepLocal.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "keep_local")...), + mysql.Arg(s.KeepLocal), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsLockssomatic retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsLockssomatic(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsLockssomatic, error) { + if len(cols) == 0 { + return LocationsLockssomatics.Query( + sm.Where(LocationsLockssomatics.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsLockssomatics.Query( + sm.Where(LocationsLockssomatics.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsLockssomatics.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsLockssomaticExists checks the presence of a single record by primary key +func LocationsLockssomaticExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsLockssomatics.Query( + sm.Where(LocationsLockssomatics.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsLockssomatic is retrieved from the database +func (o *LocationsLockssomatic) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLockssomatics.AfterSelectHooks.RunHooks(ctx, exec, LocationsLockssomaticSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsLockssomatics.AfterInsertHooks.RunHooks(ctx, exec, LocationsLockssomaticSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsLockssomatics.AfterUpdateHooks.RunHooks(ctx, exec, LocationsLockssomaticSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsLockssomatics.AfterDeleteHooks.RunHooks(ctx, exec, LocationsLockssomaticSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsLockssomatic +func (o *LocationsLockssomatic) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsLockssomatic) pkEQ() dialect.Expression { + return mysql.Quote("locations_lockssomatic", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsLockssomatic +func (o *LocationsLockssomatic) Update(ctx context.Context, exec bob.Executor, s *LocationsLockssomaticSetter) error { + _, err := LocationsLockssomatics.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsLockssomatic record with an executor +func (o *LocationsLockssomatic) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsLockssomatics.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsLockssomatic using the executor +func (o *LocationsLockssomatic) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsLockssomatics.Query( + sm.Where(LocationsLockssomatics.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsLockssomaticSlice is retrieved from the database +func (o LocationsLockssomaticSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsLockssomatics.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsLockssomatics.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsLockssomatics.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsLockssomatics.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsLockssomaticSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_lockssomatic", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsLockssomaticSlice) copyMatchingRows(from ...*LocationsLockssomatic) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsLockssomaticSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLockssomatics.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLockssomatic: + o.copyMatchingRows(retrieved) + case []*LocationsLockssomatic: + o.copyMatchingRows(retrieved...) + case LocationsLockssomaticSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLockssomatic or a slice of LocationsLockssomatic + // then run the AfterUpdateHooks on the slice + _, err = LocationsLockssomatics.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsLockssomaticSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsLockssomatics.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsLockssomatic: + o.copyMatchingRows(retrieved) + case []*LocationsLockssomatic: + o.copyMatchingRows(retrieved...) + case LocationsLockssomaticSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsLockssomatic or a slice of LocationsLockssomatic + // then run the AfterDeleteHooks on the slice + _, err = LocationsLockssomatics.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsLockssomaticSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsLockssomaticSetter) error { + _, err := LocationsLockssomatics.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsLockssomaticSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsLockssomatics.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsLockssomaticSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsLockssomatics.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsLockssomatic) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsLockssomaticSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsLockssomaticSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsLockssomatic0 *LocationsLockssomatic, locationsSpace1 *LocationsSpace) (*LocationsLockssomatic, error) { + setter := &LocationsLockssomaticSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsLockssomatic0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsLockssomaticSpaceLocationsSpace0: %w", err) + } + + return locationsLockssomatic0, nil +} + +func (locationsLockssomatic0 *LocationsLockssomatic) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsLockssomaticSpaceLocationsSpace0(ctx, exec, 1, locationsLockssomatic0, locationsSpace1) + if err != nil { + return err + } + + locationsLockssomatic0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsLockssomatic = locationsLockssomatic0 + + return nil +} + +func (locationsLockssomatic0 *LocationsLockssomatic) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsLockssomaticSpaceLocationsSpace0(ctx, exec, 1, locationsLockssomatic0, locationsSpace1) + if err != nil { + return err + } + + locationsLockssomatic0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsLockssomatic = locationsLockssomatic0 + + return nil +} + +type locationsLockssomaticWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + AuSize mysql.WhereNullMod[Q, int64] + SDIri mysql.WhereMod[Q, string] + CollectionIri mysql.WhereNullMod[Q, string] + ContentProviderID mysql.WhereMod[Q, string] + ExternalDomain mysql.WhereMod[Q, string] + ChecksumType mysql.WhereNullMod[Q, string] + KeepLocal mysql.WhereMod[Q, bool] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsLockssomaticWhere[Q]) AliasedAs(alias string) locationsLockssomaticWhere[Q] { + return buildLocationsLockssomaticWhere[Q](buildLocationsLockssomaticColumns(alias)) +} + +func buildLocationsLockssomaticWhere[Q mysql.Filterable](cols locationsLockssomaticColumns) locationsLockssomaticWhere[Q] { + return locationsLockssomaticWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + AuSize: mysql.WhereNull[Q, int64](cols.AuSize), + SDIri: mysql.Where[Q, string](cols.SDIri), + CollectionIri: mysql.WhereNull[Q, string](cols.CollectionIri), + ContentProviderID: mysql.Where[Q, string](cols.ContentProviderID), + ExternalDomain: mysql.Where[Q, string](cols.ExternalDomain), + ChecksumType: mysql.WhereNull[Q, string](cols.ChecksumType), + KeepLocal: mysql.Where[Q, bool](cols.KeepLocal), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsLockssomatic) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsLockssomatic cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsLockssomatic = o + } + return nil + default: + return fmt.Errorf("locationsLockssomatic has no relationship %q", name) + } +} + +type locationsLockssomaticPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsLockssomaticPreloader() locationsLockssomaticPreloader { + return locationsLockssomaticPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsLockssomatics, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsLockssomaticThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsLockssomaticThenLoader[Q orm.Loadable]() locationsLockssomaticThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsLockssomaticThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsLockssomatic's SpaceLocationsSpace into the .R struct +func (o *LocationsLockssomatic) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsLockssomatic = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsLockssomatic's SpaceLocationsSpace into the .R struct +func (os LocationsLockssomaticSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsLockssomatic = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsLockssomaticJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsLockssomaticJoins[Q]) aliasedAs(alias string) locationsLockssomaticJoins[Q] { + return buildLocationsLockssomaticJoins[Q](buildLocationsLockssomaticColumns(alias), j.typ) +} + +func buildLocationsLockssomaticJoins[Q dialect.Joinable](cols locationsLockssomaticColumns, typ string) locationsLockssomaticJoins[Q] { + return locationsLockssomaticJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_nfs.bob.go b/database/storage_service/models/locations_nfs.bob.go new file mode 100644 index 0000000..d5cc96d --- /dev/null +++ b/database/storage_service/models/locations_nfs.bob.go @@ -0,0 +1,688 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsNF is an object representing the database table. +type LocationsNF struct { + ID int32 `db:"id,pk,autoincr" ` + RemoteName string `db:"remote_name" ` + RemotePath string `db:"remote_path" ` + Version string `db:"version" ` + ManuallyMounted bool `db:"manually_mounted" ` + SpaceID string `db:"space_id" ` + + R locationsNFR `db:"-" ` +} + +// LocationsNFSlice is an alias for a slice of pointers to LocationsNF. +// This should almost always be used instead of []*LocationsNF. +type LocationsNFSlice []*LocationsNF + +// LocationsNFS contains methods to work with the locations_nfs table +var LocationsNFS = mysql.NewTablex[*LocationsNF, LocationsNFSlice, *LocationsNFSetter]("locations_nfs", buildLocationsNFColumns("locations_nfs"), []string{"id"}, []string{"space_id"}) + +// LocationsNFSQuery is a query on the locations_nfs table +type LocationsNFSQuery = *mysql.ViewQuery[*LocationsNF, LocationsNFSlice] + +// locationsNFR is where relationships are stored. +type locationsNFR struct { + SpaceLocationsSpace *LocationsSpace // locations_nfs_space_id_34913c3b_fk_locations_space_uuid +} + +func buildLocationsNFColumns(alias string) locationsNFColumns { + return locationsNFColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "remote_name", "remote_path", "version", "manually_mounted", "space_id", + ).WithParent("locations_nfs"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + RemoteName: mysql.Quote(alias, "remote_name"), + RemotePath: mysql.Quote(alias, "remote_path"), + Version: mysql.Quote(alias, "version"), + ManuallyMounted: mysql.Quote(alias, "manually_mounted"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsNFColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + RemoteName mysql.Expression + RemotePath mysql.Expression + Version mysql.Expression + ManuallyMounted mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsNFColumns) Alias() string { + return c.tableAlias +} + +func (locationsNFColumns) AliasedAs(alias string) locationsNFColumns { + return buildLocationsNFColumns(alias) +} + +// LocationsNFSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsNFSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + RemoteName omit.Val[string] `db:"remote_name" ` + RemotePath omit.Val[string] `db:"remote_path" ` + Version omit.Val[string] `db:"version" ` + ManuallyMounted omit.Val[bool] `db:"manually_mounted" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsNFSetter) SetColumns() []string { + vals := make([]string, 0, 6) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.RemoteName.IsValue() { + vals = append(vals, "remote_name") + } + if s.RemotePath.IsValue() { + vals = append(vals, "remote_path") + } + if s.Version.IsValue() { + vals = append(vals, "version") + } + if s.ManuallyMounted.IsValue() { + vals = append(vals, "manually_mounted") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsNFSetter) Overwrite(t *LocationsNF) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.RemoteName.IsValue() { + t.RemoteName = s.RemoteName.MustGet() + } + if s.RemotePath.IsValue() { + t.RemotePath = s.RemotePath.MustGet() + } + if s.Version.IsValue() { + t.Version = s.Version.MustGet() + } + if s.ManuallyMounted.IsValue() { + t.ManuallyMounted = s.ManuallyMounted.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsNFSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsNFS.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.RemoteName.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RemoteName.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.RemotePath.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RemotePath.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Version.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Version.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ManuallyMounted.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ManuallyMounted.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsNFSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_nfs")...) +} + +func (s LocationsNFSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 6) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.RemoteName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "remote_name")...), + mysql.Arg(s.RemoteName), + }}) + } + + if s.RemotePath.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "remote_path")...), + mysql.Arg(s.RemotePath), + }}) + } + + if s.Version.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "version")...), + mysql.Arg(s.Version), + }}) + } + + if s.ManuallyMounted.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "manually_mounted")...), + mysql.Arg(s.ManuallyMounted), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsNF retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsNF(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsNF, error) { + if len(cols) == 0 { + return LocationsNFS.Query( + sm.Where(LocationsNFS.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsNFS.Query( + sm.Where(LocationsNFS.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsNFS.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsNFExists checks the presence of a single record by primary key +func LocationsNFExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsNFS.Query( + sm.Where(LocationsNFS.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsNF is retrieved from the database +func (o *LocationsNF) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsNFS.AfterSelectHooks.RunHooks(ctx, exec, LocationsNFSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsNFS.AfterInsertHooks.RunHooks(ctx, exec, LocationsNFSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsNFS.AfterUpdateHooks.RunHooks(ctx, exec, LocationsNFSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsNFS.AfterDeleteHooks.RunHooks(ctx, exec, LocationsNFSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsNF +func (o *LocationsNF) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsNF) pkEQ() dialect.Expression { + return mysql.Quote("locations_nfs", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsNF +func (o *LocationsNF) Update(ctx context.Context, exec bob.Executor, s *LocationsNFSetter) error { + _, err := LocationsNFS.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsNF record with an executor +func (o *LocationsNF) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsNFS.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsNF using the executor +func (o *LocationsNF) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsNFS.Query( + sm.Where(LocationsNFS.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsNFSlice is retrieved from the database +func (o LocationsNFSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsNFS.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsNFS.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsNFS.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsNFS.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsNFSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_nfs", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsNFSlice) copyMatchingRows(from ...*LocationsNF) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsNFSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsNFS.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsNF: + o.copyMatchingRows(retrieved) + case []*LocationsNF: + o.copyMatchingRows(retrieved...) + case LocationsNFSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsNF or a slice of LocationsNF + // then run the AfterUpdateHooks on the slice + _, err = LocationsNFS.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsNFSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsNFS.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsNF: + o.copyMatchingRows(retrieved) + case []*LocationsNF: + o.copyMatchingRows(retrieved...) + case LocationsNFSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsNF or a slice of LocationsNF + // then run the AfterDeleteHooks on the slice + _, err = LocationsNFS.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsNFSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsNFSetter) error { + _, err := LocationsNFS.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsNFSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsNFS.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsNFSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsNFS.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsNF) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsNFSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsNFSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsNF0 *LocationsNF, locationsSpace1 *LocationsSpace) (*LocationsNF, error) { + setter := &LocationsNFSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsNF0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsNFSpaceLocationsSpace0: %w", err) + } + + return locationsNF0, nil +} + +func (locationsNF0 *LocationsNF) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsNFSpaceLocationsSpace0(ctx, exec, 1, locationsNF0, locationsSpace1) + if err != nil { + return err + } + + locationsNF0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsNF = locationsNF0 + + return nil +} + +func (locationsNF0 *LocationsNF) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsNFSpaceLocationsSpace0(ctx, exec, 1, locationsNF0, locationsSpace1) + if err != nil { + return err + } + + locationsNF0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsNF = locationsNF0 + + return nil +} + +type locationsNFWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + RemoteName mysql.WhereMod[Q, string] + RemotePath mysql.WhereMod[Q, string] + Version mysql.WhereMod[Q, string] + ManuallyMounted mysql.WhereMod[Q, bool] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsNFWhere[Q]) AliasedAs(alias string) locationsNFWhere[Q] { + return buildLocationsNFWhere[Q](buildLocationsNFColumns(alias)) +} + +func buildLocationsNFWhere[Q mysql.Filterable](cols locationsNFColumns) locationsNFWhere[Q] { + return locationsNFWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + RemoteName: mysql.Where[Q, string](cols.RemoteName), + RemotePath: mysql.Where[Q, string](cols.RemotePath), + Version: mysql.Where[Q, string](cols.Version), + ManuallyMounted: mysql.Where[Q, bool](cols.ManuallyMounted), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsNF) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsNF cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsNF = o + } + return nil + default: + return fmt.Errorf("locationsNF has no relationship %q", name) + } +} + +type locationsNFPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsNFPreloader() locationsNFPreloader { + return locationsNFPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsNFS, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsNFThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsNFThenLoader[Q orm.Loadable]() locationsNFThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsNFThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsNF's SpaceLocationsSpace into the .R struct +func (o *LocationsNF) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsNF = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsNF's SpaceLocationsSpace into the .R struct +func (os LocationsNFSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsNF = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsNFJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsNFJoins[Q]) aliasedAs(alias string) locationsNFJoins[Q] { + return buildLocationsNFJoins[Q](buildLocationsNFColumns(alias), j.typ) +} + +func buildLocationsNFJoins[Q dialect.Joinable](cols locationsNFColumns, typ string) locationsNFJoins[Q] { + return locationsNFJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_offlinereplicastaging.bob.go b/database/storage_service/models/locations_offlinereplicastaging.bob.go new file mode 100644 index 0000000..cc054ef --- /dev/null +++ b/database/storage_service/models/locations_offlinereplicastaging.bob.go @@ -0,0 +1,592 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsOfflinereplicastaging is an object representing the database table. +type LocationsOfflinereplicastaging struct { + ID int32 `db:"id,pk,autoincr" ` + SpaceID string `db:"space_id" ` + + R locationsOfflinereplicastagingR `db:"-" ` +} + +// LocationsOfflinereplicastagingSlice is an alias for a slice of pointers to LocationsOfflinereplicastaging. +// This should almost always be used instead of []*LocationsOfflinereplicastaging. +type LocationsOfflinereplicastagingSlice []*LocationsOfflinereplicastaging + +// LocationsOfflinereplicastagings contains methods to work with the locations_offlinereplicastaging table +var LocationsOfflinereplicastagings = mysql.NewTablex[*LocationsOfflinereplicastaging, LocationsOfflinereplicastagingSlice, *LocationsOfflinereplicastagingSetter]("locations_offlinereplicastaging", buildLocationsOfflinereplicastagingColumns("locations_offlinereplicastaging"), []string{"id"}, []string{"space_id"}) + +// LocationsOfflinereplicastagingsQuery is a query on the locations_offlinereplicastaging table +type LocationsOfflinereplicastagingsQuery = *mysql.ViewQuery[*LocationsOfflinereplicastaging, LocationsOfflinereplicastagingSlice] + +// locationsOfflinereplicastagingR is where relationships are stored. +type locationsOfflinereplicastagingR struct { + SpaceLocationsSpace *LocationsSpace // locations_offlinerep_space_id_2a8d7578_fk_locations +} + +func buildLocationsOfflinereplicastagingColumns(alias string) locationsOfflinereplicastagingColumns { + return locationsOfflinereplicastagingColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "space_id", + ).WithParent("locations_offlinereplicastaging"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsOfflinereplicastagingColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsOfflinereplicastagingColumns) Alias() string { + return c.tableAlias +} + +func (locationsOfflinereplicastagingColumns) AliasedAs(alias string) locationsOfflinereplicastagingColumns { + return buildLocationsOfflinereplicastagingColumns(alias) +} + +// LocationsOfflinereplicastagingSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsOfflinereplicastagingSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsOfflinereplicastagingSetter) SetColumns() []string { + vals := make([]string, 0, 2) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsOfflinereplicastagingSetter) Overwrite(t *LocationsOfflinereplicastaging) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsOfflinereplicastagingSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsOfflinereplicastagings.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsOfflinereplicastagingSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_offlinereplicastaging")...) +} + +func (s LocationsOfflinereplicastagingSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 2) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsOfflinereplicastaging retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsOfflinereplicastaging(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsOfflinereplicastaging, error) { + if len(cols) == 0 { + return LocationsOfflinereplicastagings.Query( + sm.Where(LocationsOfflinereplicastagings.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsOfflinereplicastagings.Query( + sm.Where(LocationsOfflinereplicastagings.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsOfflinereplicastagings.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsOfflinereplicastagingExists checks the presence of a single record by primary key +func LocationsOfflinereplicastagingExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsOfflinereplicastagings.Query( + sm.Where(LocationsOfflinereplicastagings.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsOfflinereplicastaging is retrieved from the database +func (o *LocationsOfflinereplicastaging) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsOfflinereplicastagings.AfterSelectHooks.RunHooks(ctx, exec, LocationsOfflinereplicastagingSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsOfflinereplicastagings.AfterInsertHooks.RunHooks(ctx, exec, LocationsOfflinereplicastagingSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsOfflinereplicastagings.AfterUpdateHooks.RunHooks(ctx, exec, LocationsOfflinereplicastagingSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsOfflinereplicastagings.AfterDeleteHooks.RunHooks(ctx, exec, LocationsOfflinereplicastagingSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsOfflinereplicastaging +func (o *LocationsOfflinereplicastaging) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsOfflinereplicastaging) pkEQ() dialect.Expression { + return mysql.Quote("locations_offlinereplicastaging", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsOfflinereplicastaging +func (o *LocationsOfflinereplicastaging) Update(ctx context.Context, exec bob.Executor, s *LocationsOfflinereplicastagingSetter) error { + _, err := LocationsOfflinereplicastagings.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsOfflinereplicastaging record with an executor +func (o *LocationsOfflinereplicastaging) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsOfflinereplicastagings.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsOfflinereplicastaging using the executor +func (o *LocationsOfflinereplicastaging) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsOfflinereplicastagings.Query( + sm.Where(LocationsOfflinereplicastagings.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsOfflinereplicastagingSlice is retrieved from the database +func (o LocationsOfflinereplicastagingSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsOfflinereplicastagings.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsOfflinereplicastagings.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsOfflinereplicastagings.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsOfflinereplicastagings.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsOfflinereplicastagingSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_offlinereplicastaging", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsOfflinereplicastagingSlice) copyMatchingRows(from ...*LocationsOfflinereplicastaging) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsOfflinereplicastagingSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsOfflinereplicastagings.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsOfflinereplicastaging: + o.copyMatchingRows(retrieved) + case []*LocationsOfflinereplicastaging: + o.copyMatchingRows(retrieved...) + case LocationsOfflinereplicastagingSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsOfflinereplicastaging or a slice of LocationsOfflinereplicastaging + // then run the AfterUpdateHooks on the slice + _, err = LocationsOfflinereplicastagings.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsOfflinereplicastagingSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsOfflinereplicastagings.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsOfflinereplicastaging: + o.copyMatchingRows(retrieved) + case []*LocationsOfflinereplicastaging: + o.copyMatchingRows(retrieved...) + case LocationsOfflinereplicastagingSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsOfflinereplicastaging or a slice of LocationsOfflinereplicastaging + // then run the AfterDeleteHooks on the slice + _, err = LocationsOfflinereplicastagings.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsOfflinereplicastagingSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsOfflinereplicastagingSetter) error { + _, err := LocationsOfflinereplicastagings.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsOfflinereplicastagingSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsOfflinereplicastagings.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsOfflinereplicastagingSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsOfflinereplicastagings.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsOfflinereplicastaging) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsOfflinereplicastagingSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsOfflinereplicastagingSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsOfflinereplicastaging0 *LocationsOfflinereplicastaging, locationsSpace1 *LocationsSpace) (*LocationsOfflinereplicastaging, error) { + setter := &LocationsOfflinereplicastagingSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsOfflinereplicastaging0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsOfflinereplicastagingSpaceLocationsSpace0: %w", err) + } + + return locationsOfflinereplicastaging0, nil +} + +func (locationsOfflinereplicastaging0 *LocationsOfflinereplicastaging) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsOfflinereplicastagingSpaceLocationsSpace0(ctx, exec, 1, locationsOfflinereplicastaging0, locationsSpace1) + if err != nil { + return err + } + + locationsOfflinereplicastaging0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsOfflinereplicastaging = locationsOfflinereplicastaging0 + + return nil +} + +func (locationsOfflinereplicastaging0 *LocationsOfflinereplicastaging) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsOfflinereplicastagingSpaceLocationsSpace0(ctx, exec, 1, locationsOfflinereplicastaging0, locationsSpace1) + if err != nil { + return err + } + + locationsOfflinereplicastaging0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsOfflinereplicastaging = locationsOfflinereplicastaging0 + + return nil +} + +type locationsOfflinereplicastagingWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsOfflinereplicastagingWhere[Q]) AliasedAs(alias string) locationsOfflinereplicastagingWhere[Q] { + return buildLocationsOfflinereplicastagingWhere[Q](buildLocationsOfflinereplicastagingColumns(alias)) +} + +func buildLocationsOfflinereplicastagingWhere[Q mysql.Filterable](cols locationsOfflinereplicastagingColumns) locationsOfflinereplicastagingWhere[Q] { + return locationsOfflinereplicastagingWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsOfflinereplicastaging) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsOfflinereplicastaging cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsOfflinereplicastaging = o + } + return nil + default: + return fmt.Errorf("locationsOfflinereplicastaging has no relationship %q", name) + } +} + +type locationsOfflinereplicastagingPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsOfflinereplicastagingPreloader() locationsOfflinereplicastagingPreloader { + return locationsOfflinereplicastagingPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsOfflinereplicastagings, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsOfflinereplicastagingThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsOfflinereplicastagingThenLoader[Q orm.Loadable]() locationsOfflinereplicastagingThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsOfflinereplicastagingThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsOfflinereplicastaging's SpaceLocationsSpace into the .R struct +func (o *LocationsOfflinereplicastaging) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsOfflinereplicastaging = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsOfflinereplicastaging's SpaceLocationsSpace into the .R struct +func (os LocationsOfflinereplicastagingSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsOfflinereplicastaging = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsOfflinereplicastagingJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsOfflinereplicastagingJoins[Q]) aliasedAs(alias string) locationsOfflinereplicastagingJoins[Q] { + return buildLocationsOfflinereplicastagingJoins[Q](buildLocationsOfflinereplicastagingColumns(alias), j.typ) +} + +func buildLocationsOfflinereplicastagingJoins[Q dialect.Joinable](cols locationsOfflinereplicastagingColumns, typ string) locationsOfflinereplicastagingJoins[Q] { + return locationsOfflinereplicastagingJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_package.bob.go b/database/storage_service/models/locations_package.bob.go new file mode 100644 index 0000000..c1714d2 --- /dev/null +++ b/database/storage_service/models/locations_package.bob.go @@ -0,0 +1,2799 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsPackage is an object representing the database table. +type LocationsPackage struct { + ID int32 `db:"id,pk,autoincr" ` + UUID string `db:"uuid" ` + CurrentPath string `db:"current_path" ` + PointerFilePath null.Val[string] `db:"pointer_file_path" ` + Size int64 `db:"size" ` + PackageType string `db:"package_type" ` + Status string `db:"status" ` + CurrentLocationID string `db:"current_location_id" ` + OriginPipelineID null.Val[string] `db:"origin_pipeline_id" ` + PointerFileLocationID null.Val[string] `db:"pointer_file_location_id" ` + MiscAttributes null.Val[string] `db:"misc_attributes" ` + Description null.Val[string] `db:"description" ` + EncryptionKeyFingerprint null.Val[string] `db:"encryption_key_fingerprint" ` + ReplicatedPackageID null.Val[string] `db:"replicated_package_id" ` + StoredDate null.Val[time.Time] `db:"stored_date" ` + Checksum null.Val[string] `db:"checksum" ` + ChecksumAlgorithm null.Val[string] `db:"checksum_algorithm" ` + + R locationsPackageR `db:"-" ` +} + +// LocationsPackageSlice is an alias for a slice of pointers to LocationsPackage. +// This should almost always be used instead of []*LocationsPackage. +type LocationsPackageSlice []*LocationsPackage + +// LocationsPackages contains methods to work with the locations_package table +var LocationsPackages = mysql.NewTablex[*LocationsPackage, LocationsPackageSlice, *LocationsPackageSetter]("locations_package", buildLocationsPackageColumns("locations_package"), []string{"id"}, []string{"uuid"}) + +// LocationsPackagesQuery is a query on the locations_package table +type LocationsPackagesQuery = *mysql.ViewQuery[*LocationsPackage, LocationsPackageSlice] + +// locationsPackageR is where relationships are stored. +type locationsPackageR struct { + PackageLocationsEvents LocationsEventSlice // locations_event_package_id_50db610f_fk_locations_package_uuid + PackageLocationsFiles LocationsFileSlice // locations_file_package_id_dd478d69_fk_locations_package_id + PackageLocationsFixitylogs LocationsFixitylogSlice // locations_fixitylog_package_id_0201e98f_fk_locations + CurrentLocationLocationsLocation *LocationsLocation // locations_package_current_location_id_c8f7daee_fk_locations + OriginPipelineLocationsPipeline *LocationsPipeline // locations_package_origin_pipeline_id_9f8d6473_fk_locations + PointerFileLocationLocationsLocation *LocationsLocation // locations_package_pointer_file_locatio_2adf5d3c_fk_locations + FromPackageLocationsPackageRelatedPackages LocationsPackageRelatedPackageSlice // locations_package_re_from_package_id_eab8b60c_fk_locations + ToPackageLocationsPackageRelatedPackages LocationsPackageRelatedPackageSlice // locations_package_re_to_package_id_7a32b99c_fk_locations + ReplicatedPackage *LocationsPackage // locations_package_replicated_package_i_6db19821_fk_locations + ReverseReplicatedPackages LocationsPackageSlice // locations_package_replicated_package_i_6db19821_fk_locations__self_join_reverse + PackageLocationsPackagedownloadtasks LocationsPackagedownloadtaskSlice // locations_packagedow_package_id_488c7751_fk_locations +} + +func buildLocationsPackageColumns(alias string) locationsPackageColumns { + return locationsPackageColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "uuid", "current_path", "pointer_file_path", "size", "package_type", "status", "current_location_id", "origin_pipeline_id", "pointer_file_location_id", "misc_attributes", "description", "encryption_key_fingerprint", "replicated_package_id", "stored_date", "checksum", "checksum_algorithm", + ).WithParent("locations_package"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UUID: mysql.Quote(alias, "uuid"), + CurrentPath: mysql.Quote(alias, "current_path"), + PointerFilePath: mysql.Quote(alias, "pointer_file_path"), + Size: mysql.Quote(alias, "size"), + PackageType: mysql.Quote(alias, "package_type"), + Status: mysql.Quote(alias, "status"), + CurrentLocationID: mysql.Quote(alias, "current_location_id"), + OriginPipelineID: mysql.Quote(alias, "origin_pipeline_id"), + PointerFileLocationID: mysql.Quote(alias, "pointer_file_location_id"), + MiscAttributes: mysql.Quote(alias, "misc_attributes"), + Description: mysql.Quote(alias, "description"), + EncryptionKeyFingerprint: mysql.Quote(alias, "encryption_key_fingerprint"), + ReplicatedPackageID: mysql.Quote(alias, "replicated_package_id"), + StoredDate: mysql.Quote(alias, "stored_date"), + Checksum: mysql.Quote(alias, "checksum"), + ChecksumAlgorithm: mysql.Quote(alias, "checksum_algorithm"), + } +} + +type locationsPackageColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UUID mysql.Expression + CurrentPath mysql.Expression + PointerFilePath mysql.Expression + Size mysql.Expression + PackageType mysql.Expression + Status mysql.Expression + CurrentLocationID mysql.Expression + OriginPipelineID mysql.Expression + PointerFileLocationID mysql.Expression + MiscAttributes mysql.Expression + Description mysql.Expression + EncryptionKeyFingerprint mysql.Expression + ReplicatedPackageID mysql.Expression + StoredDate mysql.Expression + Checksum mysql.Expression + ChecksumAlgorithm mysql.Expression +} + +func (c locationsPackageColumns) Alias() string { + return c.tableAlias +} + +func (locationsPackageColumns) AliasedAs(alias string) locationsPackageColumns { + return buildLocationsPackageColumns(alias) +} + +// LocationsPackageSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsPackageSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UUID omit.Val[string] `db:"uuid" ` + CurrentPath omit.Val[string] `db:"current_path" ` + PointerFilePath omitnull.Val[string] `db:"pointer_file_path" ` + Size omit.Val[int64] `db:"size" ` + PackageType omit.Val[string] `db:"package_type" ` + Status omit.Val[string] `db:"status" ` + CurrentLocationID omit.Val[string] `db:"current_location_id" ` + OriginPipelineID omitnull.Val[string] `db:"origin_pipeline_id" ` + PointerFileLocationID omitnull.Val[string] `db:"pointer_file_location_id" ` + MiscAttributes omitnull.Val[string] `db:"misc_attributes" ` + Description omitnull.Val[string] `db:"description" ` + EncryptionKeyFingerprint omitnull.Val[string] `db:"encryption_key_fingerprint" ` + ReplicatedPackageID omitnull.Val[string] `db:"replicated_package_id" ` + StoredDate omitnull.Val[time.Time] `db:"stored_date" ` + Checksum omitnull.Val[string] `db:"checksum" ` + ChecksumAlgorithm omitnull.Val[string] `db:"checksum_algorithm" ` +} + +func (s LocationsPackageSetter) SetColumns() []string { + vals := make([]string, 0, 17) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UUID.IsValue() { + vals = append(vals, "uuid") + } + if s.CurrentPath.IsValue() { + vals = append(vals, "current_path") + } + if !s.PointerFilePath.IsUnset() { + vals = append(vals, "pointer_file_path") + } + if s.Size.IsValue() { + vals = append(vals, "size") + } + if s.PackageType.IsValue() { + vals = append(vals, "package_type") + } + if s.Status.IsValue() { + vals = append(vals, "status") + } + if s.CurrentLocationID.IsValue() { + vals = append(vals, "current_location_id") + } + if !s.OriginPipelineID.IsUnset() { + vals = append(vals, "origin_pipeline_id") + } + if !s.PointerFileLocationID.IsUnset() { + vals = append(vals, "pointer_file_location_id") + } + if !s.MiscAttributes.IsUnset() { + vals = append(vals, "misc_attributes") + } + if !s.Description.IsUnset() { + vals = append(vals, "description") + } + if !s.EncryptionKeyFingerprint.IsUnset() { + vals = append(vals, "encryption_key_fingerprint") + } + if !s.ReplicatedPackageID.IsUnset() { + vals = append(vals, "replicated_package_id") + } + if !s.StoredDate.IsUnset() { + vals = append(vals, "stored_date") + } + if !s.Checksum.IsUnset() { + vals = append(vals, "checksum") + } + if !s.ChecksumAlgorithm.IsUnset() { + vals = append(vals, "checksum_algorithm") + } + return vals +} + +func (s LocationsPackageSetter) Overwrite(t *LocationsPackage) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UUID.IsValue() { + t.UUID = s.UUID.MustGet() + } + if s.CurrentPath.IsValue() { + t.CurrentPath = s.CurrentPath.MustGet() + } + if !s.PointerFilePath.IsUnset() { + t.PointerFilePath = s.PointerFilePath.MustGetNull() + } + if s.Size.IsValue() { + t.Size = s.Size.MustGet() + } + if s.PackageType.IsValue() { + t.PackageType = s.PackageType.MustGet() + } + if s.Status.IsValue() { + t.Status = s.Status.MustGet() + } + if s.CurrentLocationID.IsValue() { + t.CurrentLocationID = s.CurrentLocationID.MustGet() + } + if !s.OriginPipelineID.IsUnset() { + t.OriginPipelineID = s.OriginPipelineID.MustGetNull() + } + if !s.PointerFileLocationID.IsUnset() { + t.PointerFileLocationID = s.PointerFileLocationID.MustGetNull() + } + if !s.MiscAttributes.IsUnset() { + t.MiscAttributes = s.MiscAttributes.MustGetNull() + } + if !s.Description.IsUnset() { + t.Description = s.Description.MustGetNull() + } + if !s.EncryptionKeyFingerprint.IsUnset() { + t.EncryptionKeyFingerprint = s.EncryptionKeyFingerprint.MustGetNull() + } + if !s.ReplicatedPackageID.IsUnset() { + t.ReplicatedPackageID = s.ReplicatedPackageID.MustGetNull() + } + if !s.StoredDate.IsUnset() { + t.StoredDate = s.StoredDate.MustGetNull() + } + if !s.Checksum.IsUnset() { + t.Checksum = s.Checksum.MustGetNull() + } + if !s.ChecksumAlgorithm.IsUnset() { + t.ChecksumAlgorithm = s.ChecksumAlgorithm.MustGetNull() + } +} + +func (s *LocationsPackageSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackages.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UUID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UUID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.CurrentPath.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.CurrentPath.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.PointerFilePath.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PointerFilePath.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Size.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Size.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.PackageType.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PackageType.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Status.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Status.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.CurrentLocationID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.CurrentLocationID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.OriginPipelineID.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.OriginPipelineID.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.PointerFileLocationID.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PointerFileLocationID.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.MiscAttributes.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.MiscAttributes.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Description.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Description.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.EncryptionKeyFingerprint.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.EncryptionKeyFingerprint.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.ReplicatedPackageID.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ReplicatedPackageID.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.StoredDate.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.StoredDate.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Checksum.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Checksum.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.ChecksumAlgorithm.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ChecksumAlgorithm.MustGetNull()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsPackageSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_package")...) +} + +func (s LocationsPackageSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 17) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UUID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uuid")...), + mysql.Arg(s.UUID), + }}) + } + + if s.CurrentPath.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "current_path")...), + mysql.Arg(s.CurrentPath), + }}) + } + + if !s.PointerFilePath.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "pointer_file_path")...), + mysql.Arg(s.PointerFilePath), + }}) + } + + if s.Size.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "size")...), + mysql.Arg(s.Size), + }}) + } + + if s.PackageType.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "package_type")...), + mysql.Arg(s.PackageType), + }}) + } + + if s.Status.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "status")...), + mysql.Arg(s.Status), + }}) + } + + if s.CurrentLocationID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "current_location_id")...), + mysql.Arg(s.CurrentLocationID), + }}) + } + + if !s.OriginPipelineID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "origin_pipeline_id")...), + mysql.Arg(s.OriginPipelineID), + }}) + } + + if !s.PointerFileLocationID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "pointer_file_location_id")...), + mysql.Arg(s.PointerFileLocationID), + }}) + } + + if !s.MiscAttributes.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "misc_attributes")...), + mysql.Arg(s.MiscAttributes), + }}) + } + + if !s.Description.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "description")...), + mysql.Arg(s.Description), + }}) + } + + if !s.EncryptionKeyFingerprint.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "encryption_key_fingerprint")...), + mysql.Arg(s.EncryptionKeyFingerprint), + }}) + } + + if !s.ReplicatedPackageID.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "replicated_package_id")...), + mysql.Arg(s.ReplicatedPackageID), + }}) + } + + if !s.StoredDate.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "stored_date")...), + mysql.Arg(s.StoredDate), + }}) + } + + if !s.Checksum.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "checksum")...), + mysql.Arg(s.Checksum), + }}) + } + + if !s.ChecksumAlgorithm.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "checksum_algorithm")...), + mysql.Arg(s.ChecksumAlgorithm), + }}) + } + + return exprs +} + +// FindLocationsPackage retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsPackage(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsPackage, error) { + if len(cols) == 0 { + return LocationsPackages.Query( + sm.Where(LocationsPackages.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsPackages.Query( + sm.Where(LocationsPackages.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsPackages.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsPackageExists checks the presence of a single record by primary key +func LocationsPackageExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsPackages.Query( + sm.Where(LocationsPackages.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsPackage is retrieved from the database +func (o *LocationsPackage) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPackages.AfterSelectHooks.RunHooks(ctx, exec, LocationsPackageSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsPackages.AfterInsertHooks.RunHooks(ctx, exec, LocationsPackageSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsPackages.AfterUpdateHooks.RunHooks(ctx, exec, LocationsPackageSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsPackages.AfterDeleteHooks.RunHooks(ctx, exec, LocationsPackageSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsPackage +func (o *LocationsPackage) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsPackage) pkEQ() dialect.Expression { + return mysql.Quote("locations_package", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsPackage +func (o *LocationsPackage) Update(ctx context.Context, exec bob.Executor, s *LocationsPackageSetter) error { + _, err := LocationsPackages.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsPackage record with an executor +func (o *LocationsPackage) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsPackages.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsPackage using the executor +func (o *LocationsPackage) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsPackages.Query( + sm.Where(LocationsPackages.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsPackageSlice is retrieved from the database +func (o LocationsPackageSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPackages.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsPackages.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsPackages.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsPackages.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsPackageSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_package", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsPackageSlice) copyMatchingRows(from ...*LocationsPackage) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsPackageSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackages.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPackage: + o.copyMatchingRows(retrieved) + case []*LocationsPackage: + o.copyMatchingRows(retrieved...) + case LocationsPackageSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPackage or a slice of LocationsPackage + // then run the AfterUpdateHooks on the slice + _, err = LocationsPackages.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsPackageSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackages.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPackage: + o.copyMatchingRows(retrieved) + case []*LocationsPackage: + o.copyMatchingRows(retrieved...) + case LocationsPackageSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPackage or a slice of LocationsPackage + // then run the AfterDeleteHooks on the slice + _, err = LocationsPackages.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsPackageSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsPackageSetter) error { + _, err := LocationsPackages.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsPackageSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsPackages.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsPackageSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsPackages.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// PackageLocationsEvents starts a query for related objects on locations_event +func (o *LocationsPackage) PackageLocationsEvents(mods ...bob.Mod[*dialect.SelectQuery]) LocationsEventsQuery { + return LocationsEvents.Query(append(mods, + sm.Where(LocationsEvents.Columns.PackageID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsPackageSlice) PackageLocationsEvents(mods ...bob.Mod[*dialect.SelectQuery]) LocationsEventsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsEvents.Query(append(mods, + sm.Where(mysql.Group(LocationsEvents.Columns.PackageID).OP("IN", PKArgExpr)), + )...) +} + +// PackageLocationsFiles starts a query for related objects on locations_file +func (o *LocationsPackage) PackageLocationsFiles(mods ...bob.Mod[*dialect.SelectQuery]) LocationsFilesQuery { + return LocationsFiles.Query(append(mods, + sm.Where(LocationsFiles.Columns.PackageID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os LocationsPackageSlice) PackageLocationsFiles(mods ...bob.Mod[*dialect.SelectQuery]) LocationsFilesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsFiles.Query(append(mods, + sm.Where(mysql.Group(LocationsFiles.Columns.PackageID).OP("IN", PKArgExpr)), + )...) +} + +// PackageLocationsFixitylogs starts a query for related objects on locations_fixitylog +func (o *LocationsPackage) PackageLocationsFixitylogs(mods ...bob.Mod[*dialect.SelectQuery]) LocationsFixitylogsQuery { + return LocationsFixitylogs.Query(append(mods, + sm.Where(LocationsFixitylogs.Columns.PackageID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsPackageSlice) PackageLocationsFixitylogs(mods ...bob.Mod[*dialect.SelectQuery]) LocationsFixitylogsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsFixitylogs.Query(append(mods, + sm.Where(mysql.Group(LocationsFixitylogs.Columns.PackageID).OP("IN", PKArgExpr)), + )...) +} + +// CurrentLocationLocationsLocation starts a query for related objects on locations_location +func (o *LocationsPackage) CurrentLocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + return LocationsLocations.Query(append(mods, + sm.Where(LocationsLocations.Columns.UUID.EQ(mysql.Arg(o.CurrentLocationID))), + )...) +} + +func (os LocationsPackageSlice) CurrentLocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.CurrentLocationID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocations.Query(append(mods, + sm.Where(mysql.Group(LocationsLocations.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +// OriginPipelineLocationsPipeline starts a query for related objects on locations_pipeline +func (o *LocationsPackage) OriginPipelineLocationsPipeline(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPipelinesQuery { + return LocationsPipelines.Query(append(mods, + sm.Where(LocationsPipelines.Columns.UUID.EQ(mysql.Arg(o.OriginPipelineID))), + )...) +} + +func (os LocationsPackageSlice) OriginPipelineLocationsPipeline(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPipelinesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.OriginPipelineID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPipelines.Query(append(mods, + sm.Where(mysql.Group(LocationsPipelines.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +// PointerFileLocationLocationsLocation starts a query for related objects on locations_location +func (o *LocationsPackage) PointerFileLocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + return LocationsLocations.Query(append(mods, + sm.Where(LocationsLocations.Columns.UUID.EQ(mysql.Arg(o.PointerFileLocationID))), + )...) +} + +func (os LocationsPackageSlice) PointerFileLocationLocationsLocation(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PointerFileLocationID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocations.Query(append(mods, + sm.Where(mysql.Group(LocationsLocations.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +// FromPackageLocationsPackageRelatedPackages starts a query for related objects on locations_package_related_packages +func (o *LocationsPackage) FromPackageLocationsPackageRelatedPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackageRelatedPackagesQuery { + return LocationsPackageRelatedPackages.Query(append(mods, + sm.Where(LocationsPackageRelatedPackages.Columns.FromPackageID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os LocationsPackageSlice) FromPackageLocationsPackageRelatedPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackageRelatedPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackageRelatedPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackageRelatedPackages.Columns.FromPackageID).OP("IN", PKArgExpr)), + )...) +} + +// ToPackageLocationsPackageRelatedPackages starts a query for related objects on locations_package_related_packages +func (o *LocationsPackage) ToPackageLocationsPackageRelatedPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackageRelatedPackagesQuery { + return LocationsPackageRelatedPackages.Query(append(mods, + sm.Where(LocationsPackageRelatedPackages.Columns.ToPackageID.EQ(mysql.Arg(o.ID))), + )...) +} + +func (os LocationsPackageSlice) ToPackageLocationsPackageRelatedPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackageRelatedPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackageRelatedPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackageRelatedPackages.Columns.ToPackageID).OP("IN", PKArgExpr)), + )...) +} + +// ReplicatedPackage starts a query for related objects on locations_package +func (o *LocationsPackage) ReplicatedPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.UUID.EQ(mysql.Arg(o.ReplicatedPackageID))), + )...) +} + +func (os LocationsPackageSlice) ReplicatedPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ReplicatedPackageID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +// ReverseReplicatedPackages starts a query for related objects on locations_package +func (o *LocationsPackage) ReverseReplicatedPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.ReplicatedPackageID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsPackageSlice) ReverseReplicatedPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.ReplicatedPackageID).OP("IN", PKArgExpr)), + )...) +} + +// PackageLocationsPackagedownloadtasks starts a query for related objects on locations_packagedownloadtask +func (o *LocationsPackage) PackageLocationsPackagedownloadtasks(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagedownloadtasksQuery { + return LocationsPackagedownloadtasks.Query(append(mods, + sm.Where(LocationsPackagedownloadtasks.Columns.PackageID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsPackageSlice) PackageLocationsPackagedownloadtasks(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagedownloadtasksQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackagedownloadtasks.Query(append(mods, + sm.Where(mysql.Group(LocationsPackagedownloadtasks.Columns.PackageID).OP("IN", PKArgExpr)), + )...) +} + +func insertLocationsPackagePackageLocationsEvents0(ctx context.Context, exec bob.Executor, locationsEvents1 []*LocationsEventSetter, locationsPackage0 *LocationsPackage) (LocationsEventSlice, error) { + for i := range locationsEvents1 { + locationsEvents1[i].PackageID = omit.From(locationsPackage0.UUID) + } + + ret, err := LocationsEvents.Insert(bob.ToMods(locationsEvents1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPackagePackageLocationsEvents0: %w", err) + } + + return ret, nil +} + +func attachLocationsPackagePackageLocationsEvents0(ctx context.Context, exec bob.Executor, count int, locationsEvents1 LocationsEventSlice, locationsPackage0 *LocationsPackage) (LocationsEventSlice, error) { + setter := &LocationsEventSetter{ + PackageID: omit.From(locationsPackage0.UUID), + } + + err := locationsEvents1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackagePackageLocationsEvents0: %w", err) + } + + return locationsEvents1, nil +} + +func (locationsPackage0 *LocationsPackage) InsertPackageLocationsEvents(ctx context.Context, exec bob.Executor, related ...*LocationsEventSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsEvents1, err := insertLocationsPackagePackageLocationsEvents0(ctx, exec, related, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.PackageLocationsEvents = append(locationsPackage0.R.PackageLocationsEvents, locationsEvents1...) + + for _, rel := range locationsEvents1 { + rel.R.PackageLocationsPackage = locationsPackage0 + } + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachPackageLocationsEvents(ctx context.Context, exec bob.Executor, related ...*LocationsEvent) error { + if len(related) == 0 { + return nil + } + + var err error + locationsEvents1 := LocationsEventSlice(related) + + _, err = attachLocationsPackagePackageLocationsEvents0(ctx, exec, len(related), locationsEvents1, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.PackageLocationsEvents = append(locationsPackage0.R.PackageLocationsEvents, locationsEvents1...) + + for _, rel := range related { + rel.R.PackageLocationsPackage = locationsPackage0 + } + + return nil +} + +func insertLocationsPackagePackageLocationsFiles0(ctx context.Context, exec bob.Executor, locationsFiles1 []*LocationsFileSetter, locationsPackage0 *LocationsPackage) (LocationsFileSlice, error) { + for i := range locationsFiles1 { + locationsFiles1[i].PackageID = omitnull.From(locationsPackage0.ID) + } + + ret, err := LocationsFiles.Insert(bob.ToMods(locationsFiles1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPackagePackageLocationsFiles0: %w", err) + } + + return ret, nil +} + +func attachLocationsPackagePackageLocationsFiles0(ctx context.Context, exec bob.Executor, count int, locationsFiles1 LocationsFileSlice, locationsPackage0 *LocationsPackage) (LocationsFileSlice, error) { + setter := &LocationsFileSetter{ + PackageID: omitnull.From(locationsPackage0.ID), + } + + err := locationsFiles1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackagePackageLocationsFiles0: %w", err) + } + + return locationsFiles1, nil +} + +func (locationsPackage0 *LocationsPackage) InsertPackageLocationsFiles(ctx context.Context, exec bob.Executor, related ...*LocationsFileSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsFiles1, err := insertLocationsPackagePackageLocationsFiles0(ctx, exec, related, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.PackageLocationsFiles = append(locationsPackage0.R.PackageLocationsFiles, locationsFiles1...) + + for _, rel := range locationsFiles1 { + rel.R.PackageLocationsPackage = locationsPackage0 + } + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachPackageLocationsFiles(ctx context.Context, exec bob.Executor, related ...*LocationsFile) error { + if len(related) == 0 { + return nil + } + + var err error + locationsFiles1 := LocationsFileSlice(related) + + _, err = attachLocationsPackagePackageLocationsFiles0(ctx, exec, len(related), locationsFiles1, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.PackageLocationsFiles = append(locationsPackage0.R.PackageLocationsFiles, locationsFiles1...) + + for _, rel := range related { + rel.R.PackageLocationsPackage = locationsPackage0 + } + + return nil +} + +func insertLocationsPackagePackageLocationsFixitylogs0(ctx context.Context, exec bob.Executor, locationsFixitylogs1 []*LocationsFixitylogSetter, locationsPackage0 *LocationsPackage) (LocationsFixitylogSlice, error) { + for i := range locationsFixitylogs1 { + locationsFixitylogs1[i].PackageID = omit.From(locationsPackage0.UUID) + } + + ret, err := LocationsFixitylogs.Insert(bob.ToMods(locationsFixitylogs1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPackagePackageLocationsFixitylogs0: %w", err) + } + + return ret, nil +} + +func attachLocationsPackagePackageLocationsFixitylogs0(ctx context.Context, exec bob.Executor, count int, locationsFixitylogs1 LocationsFixitylogSlice, locationsPackage0 *LocationsPackage) (LocationsFixitylogSlice, error) { + setter := &LocationsFixitylogSetter{ + PackageID: omit.From(locationsPackage0.UUID), + } + + err := locationsFixitylogs1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackagePackageLocationsFixitylogs0: %w", err) + } + + return locationsFixitylogs1, nil +} + +func (locationsPackage0 *LocationsPackage) InsertPackageLocationsFixitylogs(ctx context.Context, exec bob.Executor, related ...*LocationsFixitylogSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsFixitylogs1, err := insertLocationsPackagePackageLocationsFixitylogs0(ctx, exec, related, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.PackageLocationsFixitylogs = append(locationsPackage0.R.PackageLocationsFixitylogs, locationsFixitylogs1...) + + for _, rel := range locationsFixitylogs1 { + rel.R.PackageLocationsPackage = locationsPackage0 + } + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachPackageLocationsFixitylogs(ctx context.Context, exec bob.Executor, related ...*LocationsFixitylog) error { + if len(related) == 0 { + return nil + } + + var err error + locationsFixitylogs1 := LocationsFixitylogSlice(related) + + _, err = attachLocationsPackagePackageLocationsFixitylogs0(ctx, exec, len(related), locationsFixitylogs1, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.PackageLocationsFixitylogs = append(locationsPackage0.R.PackageLocationsFixitylogs, locationsFixitylogs1...) + + for _, rel := range related { + rel.R.PackageLocationsPackage = locationsPackage0 + } + + return nil +} + +func attachLocationsPackageCurrentLocationLocationsLocation0(ctx context.Context, exec bob.Executor, count int, locationsPackage0 *LocationsPackage, locationsLocation1 *LocationsLocation) (*LocationsPackage, error) { + setter := &LocationsPackageSetter{ + CurrentLocationID: omit.From(locationsLocation1.UUID), + } + + err := locationsPackage0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackageCurrentLocationLocationsLocation0: %w", err) + } + + return locationsPackage0, nil +} + +func (locationsPackage0 *LocationsPackage) InsertCurrentLocationLocationsLocation(ctx context.Context, exec bob.Executor, related *LocationsLocationSetter) error { + var err error + + locationsLocation1, err := LocationsLocations.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPackageCurrentLocationLocationsLocation0(ctx, exec, 1, locationsPackage0, locationsLocation1) + if err != nil { + return err + } + + locationsPackage0.R.CurrentLocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.CurrentLocationLocationsPackages = append(locationsLocation1.R.CurrentLocationLocationsPackages, locationsPackage0) + + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachCurrentLocationLocationsLocation(ctx context.Context, exec bob.Executor, locationsLocation1 *LocationsLocation) error { + var err error + + _, err = attachLocationsPackageCurrentLocationLocationsLocation0(ctx, exec, 1, locationsPackage0, locationsLocation1) + if err != nil { + return err + } + + locationsPackage0.R.CurrentLocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.CurrentLocationLocationsPackages = append(locationsLocation1.R.CurrentLocationLocationsPackages, locationsPackage0) + + return nil +} + +func attachLocationsPackageOriginPipelineLocationsPipeline0(ctx context.Context, exec bob.Executor, count int, locationsPackage0 *LocationsPackage, locationsPipeline1 *LocationsPipeline) (*LocationsPackage, error) { + setter := &LocationsPackageSetter{ + OriginPipelineID: omitnull.From(locationsPipeline1.UUID), + } + + err := locationsPackage0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackageOriginPipelineLocationsPipeline0: %w", err) + } + + return locationsPackage0, nil +} + +func (locationsPackage0 *LocationsPackage) InsertOriginPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, related *LocationsPipelineSetter) error { + var err error + + locationsPipeline1, err := LocationsPipelines.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPackageOriginPipelineLocationsPipeline0(ctx, exec, 1, locationsPackage0, locationsPipeline1) + if err != nil { + return err + } + + locationsPackage0.R.OriginPipelineLocationsPipeline = locationsPipeline1 + + locationsPipeline1.R.OriginPipelineLocationsPackages = append(locationsPipeline1.R.OriginPipelineLocationsPackages, locationsPackage0) + + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachOriginPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, locationsPipeline1 *LocationsPipeline) error { + var err error + + _, err = attachLocationsPackageOriginPipelineLocationsPipeline0(ctx, exec, 1, locationsPackage0, locationsPipeline1) + if err != nil { + return err + } + + locationsPackage0.R.OriginPipelineLocationsPipeline = locationsPipeline1 + + locationsPipeline1.R.OriginPipelineLocationsPackages = append(locationsPipeline1.R.OriginPipelineLocationsPackages, locationsPackage0) + + return nil +} + +func attachLocationsPackagePointerFileLocationLocationsLocation0(ctx context.Context, exec bob.Executor, count int, locationsPackage0 *LocationsPackage, locationsLocation1 *LocationsLocation) (*LocationsPackage, error) { + setter := &LocationsPackageSetter{ + PointerFileLocationID: omitnull.From(locationsLocation1.UUID), + } + + err := locationsPackage0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackagePointerFileLocationLocationsLocation0: %w", err) + } + + return locationsPackage0, nil +} + +func (locationsPackage0 *LocationsPackage) InsertPointerFileLocationLocationsLocation(ctx context.Context, exec bob.Executor, related *LocationsLocationSetter) error { + var err error + + locationsLocation1, err := LocationsLocations.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPackagePointerFileLocationLocationsLocation0(ctx, exec, 1, locationsPackage0, locationsLocation1) + if err != nil { + return err + } + + locationsPackage0.R.PointerFileLocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.PointerFileLocationLocationsPackages = append(locationsLocation1.R.PointerFileLocationLocationsPackages, locationsPackage0) + + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachPointerFileLocationLocationsLocation(ctx context.Context, exec bob.Executor, locationsLocation1 *LocationsLocation) error { + var err error + + _, err = attachLocationsPackagePointerFileLocationLocationsLocation0(ctx, exec, 1, locationsPackage0, locationsLocation1) + if err != nil { + return err + } + + locationsPackage0.R.PointerFileLocationLocationsLocation = locationsLocation1 + + locationsLocation1.R.PointerFileLocationLocationsPackages = append(locationsLocation1.R.PointerFileLocationLocationsPackages, locationsPackage0) + + return nil +} + +func insertLocationsPackageFromPackageLocationsPackageRelatedPackages0(ctx context.Context, exec bob.Executor, locationsPackageRelatedPackages1 []*LocationsPackageRelatedPackageSetter, locationsPackage0 *LocationsPackage) (LocationsPackageRelatedPackageSlice, error) { + for i := range locationsPackageRelatedPackages1 { + locationsPackageRelatedPackages1[i].FromPackageID = omit.From(locationsPackage0.ID) + } + + ret, err := LocationsPackageRelatedPackages.Insert(bob.ToMods(locationsPackageRelatedPackages1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPackageFromPackageLocationsPackageRelatedPackages0: %w", err) + } + + return ret, nil +} + +func attachLocationsPackageFromPackageLocationsPackageRelatedPackages0(ctx context.Context, exec bob.Executor, count int, locationsPackageRelatedPackages1 LocationsPackageRelatedPackageSlice, locationsPackage0 *LocationsPackage) (LocationsPackageRelatedPackageSlice, error) { + setter := &LocationsPackageRelatedPackageSetter{ + FromPackageID: omit.From(locationsPackage0.ID), + } + + err := locationsPackageRelatedPackages1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackageFromPackageLocationsPackageRelatedPackages0: %w", err) + } + + return locationsPackageRelatedPackages1, nil +} + +func (locationsPackage0 *LocationsPackage) InsertFromPackageLocationsPackageRelatedPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackageRelatedPackageSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsPackageRelatedPackages1, err := insertLocationsPackageFromPackageLocationsPackageRelatedPackages0(ctx, exec, related, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.FromPackageLocationsPackageRelatedPackages = append(locationsPackage0.R.FromPackageLocationsPackageRelatedPackages, locationsPackageRelatedPackages1...) + + for _, rel := range locationsPackageRelatedPackages1 { + rel.R.FromPackageLocationsPackage = locationsPackage0 + } + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachFromPackageLocationsPackageRelatedPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackageRelatedPackage) error { + if len(related) == 0 { + return nil + } + + var err error + locationsPackageRelatedPackages1 := LocationsPackageRelatedPackageSlice(related) + + _, err = attachLocationsPackageFromPackageLocationsPackageRelatedPackages0(ctx, exec, len(related), locationsPackageRelatedPackages1, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.FromPackageLocationsPackageRelatedPackages = append(locationsPackage0.R.FromPackageLocationsPackageRelatedPackages, locationsPackageRelatedPackages1...) + + for _, rel := range related { + rel.R.FromPackageLocationsPackage = locationsPackage0 + } + + return nil +} + +func insertLocationsPackageToPackageLocationsPackageRelatedPackages0(ctx context.Context, exec bob.Executor, locationsPackageRelatedPackages1 []*LocationsPackageRelatedPackageSetter, locationsPackage0 *LocationsPackage) (LocationsPackageRelatedPackageSlice, error) { + for i := range locationsPackageRelatedPackages1 { + locationsPackageRelatedPackages1[i].ToPackageID = omit.From(locationsPackage0.ID) + } + + ret, err := LocationsPackageRelatedPackages.Insert(bob.ToMods(locationsPackageRelatedPackages1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPackageToPackageLocationsPackageRelatedPackages0: %w", err) + } + + return ret, nil +} + +func attachLocationsPackageToPackageLocationsPackageRelatedPackages0(ctx context.Context, exec bob.Executor, count int, locationsPackageRelatedPackages1 LocationsPackageRelatedPackageSlice, locationsPackage0 *LocationsPackage) (LocationsPackageRelatedPackageSlice, error) { + setter := &LocationsPackageRelatedPackageSetter{ + ToPackageID: omit.From(locationsPackage0.ID), + } + + err := locationsPackageRelatedPackages1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackageToPackageLocationsPackageRelatedPackages0: %w", err) + } + + return locationsPackageRelatedPackages1, nil +} + +func (locationsPackage0 *LocationsPackage) InsertToPackageLocationsPackageRelatedPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackageRelatedPackageSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsPackageRelatedPackages1, err := insertLocationsPackageToPackageLocationsPackageRelatedPackages0(ctx, exec, related, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.ToPackageLocationsPackageRelatedPackages = append(locationsPackage0.R.ToPackageLocationsPackageRelatedPackages, locationsPackageRelatedPackages1...) + + for _, rel := range locationsPackageRelatedPackages1 { + rel.R.ToPackageLocationsPackage = locationsPackage0 + } + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachToPackageLocationsPackageRelatedPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackageRelatedPackage) error { + if len(related) == 0 { + return nil + } + + var err error + locationsPackageRelatedPackages1 := LocationsPackageRelatedPackageSlice(related) + + _, err = attachLocationsPackageToPackageLocationsPackageRelatedPackages0(ctx, exec, len(related), locationsPackageRelatedPackages1, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.ToPackageLocationsPackageRelatedPackages = append(locationsPackage0.R.ToPackageLocationsPackageRelatedPackages, locationsPackageRelatedPackages1...) + + for _, rel := range related { + rel.R.ToPackageLocationsPackage = locationsPackage0 + } + + return nil +} + +func attachLocationsPackageReplicatedPackage0(ctx context.Context, exec bob.Executor, count int, locationsPackage0 *LocationsPackage, locationsPackage1 *LocationsPackage) (*LocationsPackage, error) { + setter := &LocationsPackageSetter{ + ReplicatedPackageID: omitnull.From(locationsPackage1.UUID), + } + + err := locationsPackage0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackageReplicatedPackage0: %w", err) + } + + return locationsPackage0, nil +} + +func (locationsPackage0 *LocationsPackage) InsertReplicatedPackage(ctx context.Context, exec bob.Executor, related *LocationsPackageSetter) error { + var err error + + locationsPackage1, err := LocationsPackages.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPackageReplicatedPackage0(ctx, exec, 1, locationsPackage0, locationsPackage1) + if err != nil { + return err + } + + locationsPackage0.R.ReplicatedPackage = locationsPackage1 + + locationsPackage1.R.ReplicatedPackage = locationsPackage0 + + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachReplicatedPackage(ctx context.Context, exec bob.Executor, locationsPackage1 *LocationsPackage) error { + var err error + + _, err = attachLocationsPackageReplicatedPackage0(ctx, exec, 1, locationsPackage0, locationsPackage1) + if err != nil { + return err + } + + locationsPackage0.R.ReplicatedPackage = locationsPackage1 + + locationsPackage1.R.ReplicatedPackage = locationsPackage0 + + return nil +} + +func insertLocationsPackageReverseReplicatedPackages0(ctx context.Context, exec bob.Executor, locationsPackages1 []*LocationsPackageSetter, locationsPackage0 *LocationsPackage) (LocationsPackageSlice, error) { + for i := range locationsPackages1 { + locationsPackages1[i].ReplicatedPackageID = omitnull.From(locationsPackage0.UUID) + } + + ret, err := LocationsPackages.Insert(bob.ToMods(locationsPackages1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPackageReverseReplicatedPackages0: %w", err) + } + + return ret, nil +} + +func attachLocationsPackageReverseReplicatedPackages0(ctx context.Context, exec bob.Executor, count int, locationsPackages1 LocationsPackageSlice, locationsPackage0 *LocationsPackage) (LocationsPackageSlice, error) { + setter := &LocationsPackageSetter{ + ReplicatedPackageID: omitnull.From(locationsPackage0.UUID), + } + + err := locationsPackages1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackageReverseReplicatedPackages0: %w", err) + } + + return locationsPackages1, nil +} + +func (locationsPackage0 *LocationsPackage) InsertReverseReplicatedPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackageSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsPackages1, err := insertLocationsPackageReverseReplicatedPackages0(ctx, exec, related, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.ReverseReplicatedPackages = append(locationsPackage0.R.ReverseReplicatedPackages, locationsPackages1...) + + for _, rel := range locationsPackages1 { + rel.R.ReverseReplicatedPackages = append(rel.R.ReverseReplicatedPackages, locationsPackage0) + } + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachReverseReplicatedPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackage) error { + if len(related) == 0 { + return nil + } + + var err error + locationsPackages1 := LocationsPackageSlice(related) + + _, err = attachLocationsPackageReverseReplicatedPackages0(ctx, exec, len(related), locationsPackages1, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.ReverseReplicatedPackages = append(locationsPackage0.R.ReverseReplicatedPackages, locationsPackages1...) + + for _, rel := range related { + rel.R.ReverseReplicatedPackages = append(rel.R.ReverseReplicatedPackages, locationsPackage0) + } + + return nil +} + +func insertLocationsPackagePackageLocationsPackagedownloadtasks0(ctx context.Context, exec bob.Executor, locationsPackagedownloadtasks1 []*LocationsPackagedownloadtaskSetter, locationsPackage0 *LocationsPackage) (LocationsPackagedownloadtaskSlice, error) { + for i := range locationsPackagedownloadtasks1 { + locationsPackagedownloadtasks1[i].PackageID = omit.From(locationsPackage0.UUID) + } + + ret, err := LocationsPackagedownloadtasks.Insert(bob.ToMods(locationsPackagedownloadtasks1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPackagePackageLocationsPackagedownloadtasks0: %w", err) + } + + return ret, nil +} + +func attachLocationsPackagePackageLocationsPackagedownloadtasks0(ctx context.Context, exec bob.Executor, count int, locationsPackagedownloadtasks1 LocationsPackagedownloadtaskSlice, locationsPackage0 *LocationsPackage) (LocationsPackagedownloadtaskSlice, error) { + setter := &LocationsPackagedownloadtaskSetter{ + PackageID: omit.From(locationsPackage0.UUID), + } + + err := locationsPackagedownloadtasks1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackagePackageLocationsPackagedownloadtasks0: %w", err) + } + + return locationsPackagedownloadtasks1, nil +} + +func (locationsPackage0 *LocationsPackage) InsertPackageLocationsPackagedownloadtasks(ctx context.Context, exec bob.Executor, related ...*LocationsPackagedownloadtaskSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsPackagedownloadtasks1, err := insertLocationsPackagePackageLocationsPackagedownloadtasks0(ctx, exec, related, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.PackageLocationsPackagedownloadtasks = append(locationsPackage0.R.PackageLocationsPackagedownloadtasks, locationsPackagedownloadtasks1...) + + for _, rel := range locationsPackagedownloadtasks1 { + rel.R.PackageLocationsPackage = locationsPackage0 + } + return nil +} + +func (locationsPackage0 *LocationsPackage) AttachPackageLocationsPackagedownloadtasks(ctx context.Context, exec bob.Executor, related ...*LocationsPackagedownloadtask) error { + if len(related) == 0 { + return nil + } + + var err error + locationsPackagedownloadtasks1 := LocationsPackagedownloadtaskSlice(related) + + _, err = attachLocationsPackagePackageLocationsPackagedownloadtasks0(ctx, exec, len(related), locationsPackagedownloadtasks1, locationsPackage0) + if err != nil { + return err + } + + locationsPackage0.R.PackageLocationsPackagedownloadtasks = append(locationsPackage0.R.PackageLocationsPackagedownloadtasks, locationsPackagedownloadtasks1...) + + for _, rel := range related { + rel.R.PackageLocationsPackage = locationsPackage0 + } + + return nil +} + +type locationsPackageWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UUID mysql.WhereMod[Q, string] + CurrentPath mysql.WhereMod[Q, string] + PointerFilePath mysql.WhereNullMod[Q, string] + Size mysql.WhereMod[Q, int64] + PackageType mysql.WhereMod[Q, string] + Status mysql.WhereMod[Q, string] + CurrentLocationID mysql.WhereMod[Q, string] + OriginPipelineID mysql.WhereNullMod[Q, string] + PointerFileLocationID mysql.WhereNullMod[Q, string] + MiscAttributes mysql.WhereNullMod[Q, string] + Description mysql.WhereNullMod[Q, string] + EncryptionKeyFingerprint mysql.WhereNullMod[Q, string] + ReplicatedPackageID mysql.WhereNullMod[Q, string] + StoredDate mysql.WhereNullMod[Q, time.Time] + Checksum mysql.WhereNullMod[Q, string] + ChecksumAlgorithm mysql.WhereNullMod[Q, string] +} + +func (locationsPackageWhere[Q]) AliasedAs(alias string) locationsPackageWhere[Q] { + return buildLocationsPackageWhere[Q](buildLocationsPackageColumns(alias)) +} + +func buildLocationsPackageWhere[Q mysql.Filterable](cols locationsPackageColumns) locationsPackageWhere[Q] { + return locationsPackageWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UUID: mysql.Where[Q, string](cols.UUID), + CurrentPath: mysql.Where[Q, string](cols.CurrentPath), + PointerFilePath: mysql.WhereNull[Q, string](cols.PointerFilePath), + Size: mysql.Where[Q, int64](cols.Size), + PackageType: mysql.Where[Q, string](cols.PackageType), + Status: mysql.Where[Q, string](cols.Status), + CurrentLocationID: mysql.Where[Q, string](cols.CurrentLocationID), + OriginPipelineID: mysql.WhereNull[Q, string](cols.OriginPipelineID), + PointerFileLocationID: mysql.WhereNull[Q, string](cols.PointerFileLocationID), + MiscAttributes: mysql.WhereNull[Q, string](cols.MiscAttributes), + Description: mysql.WhereNull[Q, string](cols.Description), + EncryptionKeyFingerprint: mysql.WhereNull[Q, string](cols.EncryptionKeyFingerprint), + ReplicatedPackageID: mysql.WhereNull[Q, string](cols.ReplicatedPackageID), + StoredDate: mysql.WhereNull[Q, time.Time](cols.StoredDate), + Checksum: mysql.WhereNull[Q, string](cols.Checksum), + ChecksumAlgorithm: mysql.WhereNull[Q, string](cols.ChecksumAlgorithm), + } +} + +func (o *LocationsPackage) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "PackageLocationsEvents": + rels, ok := retrieved.(LocationsEventSlice) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.PackageLocationsEvents = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PackageLocationsPackage = o + } + } + return nil + case "PackageLocationsFiles": + rels, ok := retrieved.(LocationsFileSlice) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.PackageLocationsFiles = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PackageLocationsPackage = o + } + } + return nil + case "PackageLocationsFixitylogs": + rels, ok := retrieved.(LocationsFixitylogSlice) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.PackageLocationsFixitylogs = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PackageLocationsPackage = o + } + } + return nil + case "CurrentLocationLocationsLocation": + rel, ok := retrieved.(*LocationsLocation) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.CurrentLocationLocationsLocation = rel + + if rel != nil { + rel.R.CurrentLocationLocationsPackages = LocationsPackageSlice{o} + } + return nil + case "OriginPipelineLocationsPipeline": + rel, ok := retrieved.(*LocationsPipeline) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.OriginPipelineLocationsPipeline = rel + + if rel != nil { + rel.R.OriginPipelineLocationsPackages = LocationsPackageSlice{o} + } + return nil + case "PointerFileLocationLocationsLocation": + rel, ok := retrieved.(*LocationsLocation) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.PointerFileLocationLocationsLocation = rel + + if rel != nil { + rel.R.PointerFileLocationLocationsPackages = LocationsPackageSlice{o} + } + return nil + case "FromPackageLocationsPackageRelatedPackages": + rels, ok := retrieved.(LocationsPackageRelatedPackageSlice) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.FromPackageLocationsPackageRelatedPackages = rels + + for _, rel := range rels { + if rel != nil { + rel.R.FromPackageLocationsPackage = o + } + } + return nil + case "ToPackageLocationsPackageRelatedPackages": + rels, ok := retrieved.(LocationsPackageRelatedPackageSlice) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.ToPackageLocationsPackageRelatedPackages = rels + + for _, rel := range rels { + if rel != nil { + rel.R.ToPackageLocationsPackage = o + } + } + return nil + case "ReplicatedPackage": + rel, ok := retrieved.(*LocationsPackage) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.ReplicatedPackage = rel + + if rel != nil { + rel.R.ReplicatedPackage = o + } + return nil + case "ReverseReplicatedPackages": + rels, ok := retrieved.(LocationsPackageSlice) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.ReverseReplicatedPackages = rels + + for _, rel := range rels { + if rel != nil { + rel.R.ReverseReplicatedPackages = LocationsPackageSlice{o} + } + } + return nil + case "PackageLocationsPackagedownloadtasks": + rels, ok := retrieved.(LocationsPackagedownloadtaskSlice) + if !ok { + return fmt.Errorf("locationsPackage cannot load %T as %q", retrieved, name) + } + + o.R.PackageLocationsPackagedownloadtasks = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PackageLocationsPackage = o + } + } + return nil + default: + return fmt.Errorf("locationsPackage has no relationship %q", name) + } +} + +type locationsPackagePreloader struct { + CurrentLocationLocationsLocation func(...mysql.PreloadOption) mysql.Preloader + OriginPipelineLocationsPipeline func(...mysql.PreloadOption) mysql.Preloader + PointerFileLocationLocationsLocation func(...mysql.PreloadOption) mysql.Preloader + ReplicatedPackage func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsPackagePreloader() locationsPackagePreloader { + return locationsPackagePreloader{ + CurrentLocationLocationsLocation: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsLocation, LocationsLocationSlice](mysql.PreloadRel{ + Name: "CurrentLocationLocationsLocation", + Sides: []mysql.PreloadSide{ + { + From: LocationsPackages, + To: LocationsLocations, + FromColumns: []string{"current_location_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsLocations.Columns.Names(), opts...) + }, + OriginPipelineLocationsPipeline: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPipeline, LocationsPipelineSlice](mysql.PreloadRel{ + Name: "OriginPipelineLocationsPipeline", + Sides: []mysql.PreloadSide{ + { + From: LocationsPackages, + To: LocationsPipelines, + FromColumns: []string{"origin_pipeline_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsPipelines.Columns.Names(), opts...) + }, + PointerFileLocationLocationsLocation: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsLocation, LocationsLocationSlice](mysql.PreloadRel{ + Name: "PointerFileLocationLocationsLocation", + Sides: []mysql.PreloadSide{ + { + From: LocationsPackages, + To: LocationsLocations, + FromColumns: []string{"pointer_file_location_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsLocations.Columns.Names(), opts...) + }, + ReplicatedPackage: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPackage, LocationsPackageSlice](mysql.PreloadRel{ + Name: "ReplicatedPackage", + Sides: []mysql.PreloadSide{ + { + From: LocationsPackages, + To: LocationsPackages, + FromColumns: []string{"replicated_package_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsPackages.Columns.Names(), opts...) + }, + } +} + +type locationsPackageThenLoader[Q orm.Loadable] struct { + PackageLocationsEvents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PackageLocationsFiles func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PackageLocationsFixitylogs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + CurrentLocationLocationsLocation func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + OriginPipelineLocationsPipeline func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PointerFileLocationLocationsLocation func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + FromPackageLocationsPackageRelatedPackages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ToPackageLocationsPackageRelatedPackages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ReplicatedPackage func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ReverseReplicatedPackages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PackageLocationsPackagedownloadtasks func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsPackageThenLoader[Q orm.Loadable]() locationsPackageThenLoader[Q] { + type PackageLocationsEventsLoadInterface interface { + LoadPackageLocationsEvents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PackageLocationsFilesLoadInterface interface { + LoadPackageLocationsFiles(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PackageLocationsFixitylogsLoadInterface interface { + LoadPackageLocationsFixitylogs(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type CurrentLocationLocationsLocationLoadInterface interface { + LoadCurrentLocationLocationsLocation(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type OriginPipelineLocationsPipelineLoadInterface interface { + LoadOriginPipelineLocationsPipeline(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PointerFileLocationLocationsLocationLoadInterface interface { + LoadPointerFileLocationLocationsLocation(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type FromPackageLocationsPackageRelatedPackagesLoadInterface interface { + LoadFromPackageLocationsPackageRelatedPackages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ToPackageLocationsPackageRelatedPackagesLoadInterface interface { + LoadToPackageLocationsPackageRelatedPackages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ReplicatedPackageLoadInterface interface { + LoadReplicatedPackage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ReverseReplicatedPackagesLoadInterface interface { + LoadReverseReplicatedPackages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PackageLocationsPackagedownloadtasksLoadInterface interface { + LoadPackageLocationsPackagedownloadtasks(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsPackageThenLoader[Q]{ + PackageLocationsEvents: thenLoadBuilder[Q]( + "PackageLocationsEvents", + func(ctx context.Context, exec bob.Executor, retrieved PackageLocationsEventsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPackageLocationsEvents(ctx, exec, mods...) + }, + ), + PackageLocationsFiles: thenLoadBuilder[Q]( + "PackageLocationsFiles", + func(ctx context.Context, exec bob.Executor, retrieved PackageLocationsFilesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPackageLocationsFiles(ctx, exec, mods...) + }, + ), + PackageLocationsFixitylogs: thenLoadBuilder[Q]( + "PackageLocationsFixitylogs", + func(ctx context.Context, exec bob.Executor, retrieved PackageLocationsFixitylogsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPackageLocationsFixitylogs(ctx, exec, mods...) + }, + ), + CurrentLocationLocationsLocation: thenLoadBuilder[Q]( + "CurrentLocationLocationsLocation", + func(ctx context.Context, exec bob.Executor, retrieved CurrentLocationLocationsLocationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadCurrentLocationLocationsLocation(ctx, exec, mods...) + }, + ), + OriginPipelineLocationsPipeline: thenLoadBuilder[Q]( + "OriginPipelineLocationsPipeline", + func(ctx context.Context, exec bob.Executor, retrieved OriginPipelineLocationsPipelineLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadOriginPipelineLocationsPipeline(ctx, exec, mods...) + }, + ), + PointerFileLocationLocationsLocation: thenLoadBuilder[Q]( + "PointerFileLocationLocationsLocation", + func(ctx context.Context, exec bob.Executor, retrieved PointerFileLocationLocationsLocationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPointerFileLocationLocationsLocation(ctx, exec, mods...) + }, + ), + FromPackageLocationsPackageRelatedPackages: thenLoadBuilder[Q]( + "FromPackageLocationsPackageRelatedPackages", + func(ctx context.Context, exec bob.Executor, retrieved FromPackageLocationsPackageRelatedPackagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadFromPackageLocationsPackageRelatedPackages(ctx, exec, mods...) + }, + ), + ToPackageLocationsPackageRelatedPackages: thenLoadBuilder[Q]( + "ToPackageLocationsPackageRelatedPackages", + func(ctx context.Context, exec bob.Executor, retrieved ToPackageLocationsPackageRelatedPackagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadToPackageLocationsPackageRelatedPackages(ctx, exec, mods...) + }, + ), + ReplicatedPackage: thenLoadBuilder[Q]( + "ReplicatedPackage", + func(ctx context.Context, exec bob.Executor, retrieved ReplicatedPackageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadReplicatedPackage(ctx, exec, mods...) + }, + ), + ReverseReplicatedPackages: thenLoadBuilder[Q]( + "ReverseReplicatedPackages", + func(ctx context.Context, exec bob.Executor, retrieved ReverseReplicatedPackagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadReverseReplicatedPackages(ctx, exec, mods...) + }, + ), + PackageLocationsPackagedownloadtasks: thenLoadBuilder[Q]( + "PackageLocationsPackagedownloadtasks", + func(ctx context.Context, exec bob.Executor, retrieved PackageLocationsPackagedownloadtasksLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPackageLocationsPackagedownloadtasks(ctx, exec, mods...) + }, + ), + } +} + +// LoadPackageLocationsEvents loads the locationsPackage's PackageLocationsEvents into the .R struct +func (o *LocationsPackage) LoadPackageLocationsEvents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PackageLocationsEvents = nil + + related, err := o.PackageLocationsEvents(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PackageLocationsPackage = o + } + + o.R.PackageLocationsEvents = related + return nil +} + +// LoadPackageLocationsEvents loads the locationsPackage's PackageLocationsEvents into the .R struct +func (os LocationsPackageSlice) LoadPackageLocationsEvents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsEvents, err := os.PackageLocationsEvents(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PackageLocationsEvents = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsEvents { + + if !(o.UUID == rel.PackageID) { + continue + } + + rel.R.PackageLocationsPackage = o + + o.R.PackageLocationsEvents = append(o.R.PackageLocationsEvents, rel) + } + } + + return nil +} + +// LoadPackageLocationsFiles loads the locationsPackage's PackageLocationsFiles into the .R struct +func (o *LocationsPackage) LoadPackageLocationsFiles(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PackageLocationsFiles = nil + + related, err := o.PackageLocationsFiles(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PackageLocationsPackage = o + } + + o.R.PackageLocationsFiles = related + return nil +} + +// LoadPackageLocationsFiles loads the locationsPackage's PackageLocationsFiles into the .R struct +func (os LocationsPackageSlice) LoadPackageLocationsFiles(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsFiles, err := os.PackageLocationsFiles(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PackageLocationsFiles = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsFiles { + + if !rel.PackageID.IsValue() { + continue + } + if !(rel.PackageID.IsValue() && o.ID == rel.PackageID.MustGet()) { + continue + } + + rel.R.PackageLocationsPackage = o + + o.R.PackageLocationsFiles = append(o.R.PackageLocationsFiles, rel) + } + } + + return nil +} + +// LoadPackageLocationsFixitylogs loads the locationsPackage's PackageLocationsFixitylogs into the .R struct +func (o *LocationsPackage) LoadPackageLocationsFixitylogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PackageLocationsFixitylogs = nil + + related, err := o.PackageLocationsFixitylogs(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PackageLocationsPackage = o + } + + o.R.PackageLocationsFixitylogs = related + return nil +} + +// LoadPackageLocationsFixitylogs loads the locationsPackage's PackageLocationsFixitylogs into the .R struct +func (os LocationsPackageSlice) LoadPackageLocationsFixitylogs(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsFixitylogs, err := os.PackageLocationsFixitylogs(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PackageLocationsFixitylogs = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsFixitylogs { + + if !(o.UUID == rel.PackageID) { + continue + } + + rel.R.PackageLocationsPackage = o + + o.R.PackageLocationsFixitylogs = append(o.R.PackageLocationsFixitylogs, rel) + } + } + + return nil +} + +// LoadCurrentLocationLocationsLocation loads the locationsPackage's CurrentLocationLocationsLocation into the .R struct +func (o *LocationsPackage) LoadCurrentLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.CurrentLocationLocationsLocation = nil + + related, err := o.CurrentLocationLocationsLocation(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.CurrentLocationLocationsPackages = LocationsPackageSlice{o} + + o.R.CurrentLocationLocationsLocation = related + return nil +} + +// LoadCurrentLocationLocationsLocation loads the locationsPackage's CurrentLocationLocationsLocation into the .R struct +func (os LocationsPackageSlice) LoadCurrentLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocations, err := os.CurrentLocationLocationsLocation(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocations { + + if !(o.CurrentLocationID == rel.UUID) { + continue + } + + rel.R.CurrentLocationLocationsPackages = append(rel.R.CurrentLocationLocationsPackages, o) + + o.R.CurrentLocationLocationsLocation = rel + break + } + } + + return nil +} + +// LoadOriginPipelineLocationsPipeline loads the locationsPackage's OriginPipelineLocationsPipeline into the .R struct +func (o *LocationsPackage) LoadOriginPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.OriginPipelineLocationsPipeline = nil + + related, err := o.OriginPipelineLocationsPipeline(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.OriginPipelineLocationsPackages = LocationsPackageSlice{o} + + o.R.OriginPipelineLocationsPipeline = related + return nil +} + +// LoadOriginPipelineLocationsPipeline loads the locationsPackage's OriginPipelineLocationsPipeline into the .R struct +func (os LocationsPackageSlice) LoadOriginPipelineLocationsPipeline(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPipelines, err := os.OriginPipelineLocationsPipeline(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPipelines { + if !o.OriginPipelineID.IsValue() { + continue + } + + if !(o.OriginPipelineID.IsValue() && o.OriginPipelineID.MustGet() == rel.UUID) { + continue + } + + rel.R.OriginPipelineLocationsPackages = append(rel.R.OriginPipelineLocationsPackages, o) + + o.R.OriginPipelineLocationsPipeline = rel + break + } + } + + return nil +} + +// LoadPointerFileLocationLocationsLocation loads the locationsPackage's PointerFileLocationLocationsLocation into the .R struct +func (o *LocationsPackage) LoadPointerFileLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PointerFileLocationLocationsLocation = nil + + related, err := o.PointerFileLocationLocationsLocation(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PointerFileLocationLocationsPackages = LocationsPackageSlice{o} + + o.R.PointerFileLocationLocationsLocation = related + return nil +} + +// LoadPointerFileLocationLocationsLocation loads the locationsPackage's PointerFileLocationLocationsLocation into the .R struct +func (os LocationsPackageSlice) LoadPointerFileLocationLocationsLocation(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocations, err := os.PointerFileLocationLocationsLocation(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocations { + if !o.PointerFileLocationID.IsValue() { + continue + } + + if !(o.PointerFileLocationID.IsValue() && o.PointerFileLocationID.MustGet() == rel.UUID) { + continue + } + + rel.R.PointerFileLocationLocationsPackages = append(rel.R.PointerFileLocationLocationsPackages, o) + + o.R.PointerFileLocationLocationsLocation = rel + break + } + } + + return nil +} + +// LoadFromPackageLocationsPackageRelatedPackages loads the locationsPackage's FromPackageLocationsPackageRelatedPackages into the .R struct +func (o *LocationsPackage) LoadFromPackageLocationsPackageRelatedPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.FromPackageLocationsPackageRelatedPackages = nil + + related, err := o.FromPackageLocationsPackageRelatedPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.FromPackageLocationsPackage = o + } + + o.R.FromPackageLocationsPackageRelatedPackages = related + return nil +} + +// LoadFromPackageLocationsPackageRelatedPackages loads the locationsPackage's FromPackageLocationsPackageRelatedPackages into the .R struct +func (os LocationsPackageSlice) LoadFromPackageLocationsPackageRelatedPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackageRelatedPackages, err := os.FromPackageLocationsPackageRelatedPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.FromPackageLocationsPackageRelatedPackages = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackageRelatedPackages { + + if !(o.ID == rel.FromPackageID) { + continue + } + + rel.R.FromPackageLocationsPackage = o + + o.R.FromPackageLocationsPackageRelatedPackages = append(o.R.FromPackageLocationsPackageRelatedPackages, rel) + } + } + + return nil +} + +// LoadToPackageLocationsPackageRelatedPackages loads the locationsPackage's ToPackageLocationsPackageRelatedPackages into the .R struct +func (o *LocationsPackage) LoadToPackageLocationsPackageRelatedPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ToPackageLocationsPackageRelatedPackages = nil + + related, err := o.ToPackageLocationsPackageRelatedPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.ToPackageLocationsPackage = o + } + + o.R.ToPackageLocationsPackageRelatedPackages = related + return nil +} + +// LoadToPackageLocationsPackageRelatedPackages loads the locationsPackage's ToPackageLocationsPackageRelatedPackages into the .R struct +func (os LocationsPackageSlice) LoadToPackageLocationsPackageRelatedPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackageRelatedPackages, err := os.ToPackageLocationsPackageRelatedPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.ToPackageLocationsPackageRelatedPackages = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackageRelatedPackages { + + if !(o.ID == rel.ToPackageID) { + continue + } + + rel.R.ToPackageLocationsPackage = o + + o.R.ToPackageLocationsPackageRelatedPackages = append(o.R.ToPackageLocationsPackageRelatedPackages, rel) + } + } + + return nil +} + +// LoadReplicatedPackage loads the locationsPackage's ReplicatedPackage into the .R struct +func (o *LocationsPackage) LoadReplicatedPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ReplicatedPackage = nil + + related, err := o.ReplicatedPackage(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.ReplicatedPackage = o + + o.R.ReplicatedPackage = related + return nil +} + +// LoadReplicatedPackage loads the locationsPackage's ReplicatedPackage into the .R struct +func (os LocationsPackageSlice) LoadReplicatedPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.ReplicatedPackage(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + if !o.ReplicatedPackageID.IsValue() { + continue + } + + if !(o.ReplicatedPackageID.IsValue() && o.ReplicatedPackageID.MustGet() == rel.UUID) { + continue + } + + rel.R.ReplicatedPackage = o + + o.R.ReplicatedPackage = rel + break + } + } + + return nil +} + +// LoadReverseReplicatedPackages loads the locationsPackage's ReverseReplicatedPackages into the .R struct +func (o *LocationsPackage) LoadReverseReplicatedPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ReverseReplicatedPackages = nil + + related, err := o.ReverseReplicatedPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.ReverseReplicatedPackages = LocationsPackageSlice{o} + } + + o.R.ReverseReplicatedPackages = related + return nil +} + +// LoadReverseReplicatedPackages loads the locationsPackage's ReverseReplicatedPackages into the .R struct +func (os LocationsPackageSlice) LoadReverseReplicatedPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.ReverseReplicatedPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.ReverseReplicatedPackages = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !rel.ReplicatedPackageID.IsValue() { + continue + } + if !(rel.ReplicatedPackageID.IsValue() && o.UUID == rel.ReplicatedPackageID.MustGet()) { + continue + } + + rel.R.ReverseReplicatedPackages = append(rel.R.ReverseReplicatedPackages, o) + + o.R.ReverseReplicatedPackages = append(o.R.ReverseReplicatedPackages, rel) + } + } + + return nil +} + +// LoadPackageLocationsPackagedownloadtasks loads the locationsPackage's PackageLocationsPackagedownloadtasks into the .R struct +func (o *LocationsPackage) LoadPackageLocationsPackagedownloadtasks(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PackageLocationsPackagedownloadtasks = nil + + related, err := o.PackageLocationsPackagedownloadtasks(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PackageLocationsPackage = o + } + + o.R.PackageLocationsPackagedownloadtasks = related + return nil +} + +// LoadPackageLocationsPackagedownloadtasks loads the locationsPackage's PackageLocationsPackagedownloadtasks into the .R struct +func (os LocationsPackageSlice) LoadPackageLocationsPackagedownloadtasks(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackagedownloadtasks, err := os.PackageLocationsPackagedownloadtasks(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PackageLocationsPackagedownloadtasks = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackagedownloadtasks { + + if !(o.UUID == rel.PackageID) { + continue + } + + rel.R.PackageLocationsPackage = o + + o.R.PackageLocationsPackagedownloadtasks = append(o.R.PackageLocationsPackagedownloadtasks, rel) + } + } + + return nil +} + +type locationsPackageJoins[Q dialect.Joinable] struct { + typ string + PackageLocationsEvents modAs[Q, locationsEventColumns] + PackageLocationsFiles modAs[Q, locationsFileColumns] + PackageLocationsFixitylogs modAs[Q, locationsFixitylogColumns] + CurrentLocationLocationsLocation modAs[Q, locationsLocationColumns] + OriginPipelineLocationsPipeline modAs[Q, locationsPipelineColumns] + PointerFileLocationLocationsLocation modAs[Q, locationsLocationColumns] + FromPackageLocationsPackageRelatedPackages modAs[Q, locationsPackageRelatedPackageColumns] + ToPackageLocationsPackageRelatedPackages modAs[Q, locationsPackageRelatedPackageColumns] + ReplicatedPackage modAs[Q, locationsPackageColumns] + ReverseReplicatedPackages modAs[Q, locationsPackageColumns] + PackageLocationsPackagedownloadtasks modAs[Q, locationsPackagedownloadtaskColumns] +} + +func (j locationsPackageJoins[Q]) aliasedAs(alias string) locationsPackageJoins[Q] { + return buildLocationsPackageJoins[Q](buildLocationsPackageColumns(alias), j.typ) +} + +func buildLocationsPackageJoins[Q dialect.Joinable](cols locationsPackageColumns, typ string) locationsPackageJoins[Q] { + return locationsPackageJoins[Q]{ + typ: typ, + PackageLocationsEvents: modAs[Q, locationsEventColumns]{ + c: LocationsEvents.Columns, + f: func(to locationsEventColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsEvents.Name().As(to.Alias())).On( + to.PackageID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + PackageLocationsFiles: modAs[Q, locationsFileColumns]{ + c: LocationsFiles.Columns, + f: func(to locationsFileColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsFiles.Name().As(to.Alias())).On( + to.PackageID.EQ(cols.ID), + )) + } + + return mods + }, + }, + PackageLocationsFixitylogs: modAs[Q, locationsFixitylogColumns]{ + c: LocationsFixitylogs.Columns, + f: func(to locationsFixitylogColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsFixitylogs.Name().As(to.Alias())).On( + to.PackageID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + CurrentLocationLocationsLocation: modAs[Q, locationsLocationColumns]{ + c: LocationsLocations.Columns, + f: func(to locationsLocationColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocations.Name().As(to.Alias())).On( + to.UUID.EQ(cols.CurrentLocationID), + )) + } + + return mods + }, + }, + OriginPipelineLocationsPipeline: modAs[Q, locationsPipelineColumns]{ + c: LocationsPipelines.Columns, + f: func(to locationsPipelineColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPipelines.Name().As(to.Alias())).On( + to.UUID.EQ(cols.OriginPipelineID), + )) + } + + return mods + }, + }, + PointerFileLocationLocationsLocation: modAs[Q, locationsLocationColumns]{ + c: LocationsLocations.Columns, + f: func(to locationsLocationColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocations.Name().As(to.Alias())).On( + to.UUID.EQ(cols.PointerFileLocationID), + )) + } + + return mods + }, + }, + FromPackageLocationsPackageRelatedPackages: modAs[Q, locationsPackageRelatedPackageColumns]{ + c: LocationsPackageRelatedPackages.Columns, + f: func(to locationsPackageRelatedPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackageRelatedPackages.Name().As(to.Alias())).On( + to.FromPackageID.EQ(cols.ID), + )) + } + + return mods + }, + }, + ToPackageLocationsPackageRelatedPackages: modAs[Q, locationsPackageRelatedPackageColumns]{ + c: LocationsPackageRelatedPackages.Columns, + f: func(to locationsPackageRelatedPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackageRelatedPackages.Name().As(to.Alias())).On( + to.ToPackageID.EQ(cols.ID), + )) + } + + return mods + }, + }, + ReplicatedPackage: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.UUID.EQ(cols.ReplicatedPackageID), + )) + } + + return mods + }, + }, + ReverseReplicatedPackages: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.ReplicatedPackageID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + PackageLocationsPackagedownloadtasks: modAs[Q, locationsPackagedownloadtaskColumns]{ + c: LocationsPackagedownloadtasks.Columns, + f: func(to locationsPackagedownloadtaskColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackagedownloadtasks.Name().As(to.Alias())).On( + to.PackageID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_package_related_packages.bob.go b/database/storage_service/models/locations_package_related_packages.bob.go new file mode 100644 index 0000000..7ff373e --- /dev/null +++ b/database/storage_service/models/locations_package_related_packages.bob.go @@ -0,0 +1,787 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsPackageRelatedPackage is an object representing the database table. +type LocationsPackageRelatedPackage struct { + ID int32 `db:"id,pk,autoincr" ` + FromPackageID int32 `db:"from_package_id" ` + ToPackageID int32 `db:"to_package_id" ` + + R locationsPackageRelatedPackageR `db:"-" ` +} + +// LocationsPackageRelatedPackageSlice is an alias for a slice of pointers to LocationsPackageRelatedPackage. +// This should almost always be used instead of []*LocationsPackageRelatedPackage. +type LocationsPackageRelatedPackageSlice []*LocationsPackageRelatedPackage + +// LocationsPackageRelatedPackages contains methods to work with the locations_package_related_packages table +var LocationsPackageRelatedPackages = mysql.NewTablex[*LocationsPackageRelatedPackage, LocationsPackageRelatedPackageSlice, *LocationsPackageRelatedPackageSetter]("locations_package_related_packages", buildLocationsPackageRelatedPackageColumns("locations_package_related_packages"), []string{"id"}, []string{"from_package_id", "to_package_id"}) + +// LocationsPackageRelatedPackagesQuery is a query on the locations_package_related_packages table +type LocationsPackageRelatedPackagesQuery = *mysql.ViewQuery[*LocationsPackageRelatedPackage, LocationsPackageRelatedPackageSlice] + +// locationsPackageRelatedPackageR is where relationships are stored. +type locationsPackageRelatedPackageR struct { + FromPackageLocationsPackage *LocationsPackage // locations_package_re_from_package_id_eab8b60c_fk_locations + ToPackageLocationsPackage *LocationsPackage // locations_package_re_to_package_id_7a32b99c_fk_locations +} + +func buildLocationsPackageRelatedPackageColumns(alias string) locationsPackageRelatedPackageColumns { + return locationsPackageRelatedPackageColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "from_package_id", "to_package_id", + ).WithParent("locations_package_related_packages"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + FromPackageID: mysql.Quote(alias, "from_package_id"), + ToPackageID: mysql.Quote(alias, "to_package_id"), + } +} + +type locationsPackageRelatedPackageColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + FromPackageID mysql.Expression + ToPackageID mysql.Expression +} + +func (c locationsPackageRelatedPackageColumns) Alias() string { + return c.tableAlias +} + +func (locationsPackageRelatedPackageColumns) AliasedAs(alias string) locationsPackageRelatedPackageColumns { + return buildLocationsPackageRelatedPackageColumns(alias) +} + +// LocationsPackageRelatedPackageSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsPackageRelatedPackageSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + FromPackageID omit.Val[int32] `db:"from_package_id" ` + ToPackageID omit.Val[int32] `db:"to_package_id" ` +} + +func (s LocationsPackageRelatedPackageSetter) SetColumns() []string { + vals := make([]string, 0, 3) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.FromPackageID.IsValue() { + vals = append(vals, "from_package_id") + } + if s.ToPackageID.IsValue() { + vals = append(vals, "to_package_id") + } + return vals +} + +func (s LocationsPackageRelatedPackageSetter) Overwrite(t *LocationsPackageRelatedPackage) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.FromPackageID.IsValue() { + t.FromPackageID = s.FromPackageID.MustGet() + } + if s.ToPackageID.IsValue() { + t.ToPackageID = s.ToPackageID.MustGet() + } +} + +func (s *LocationsPackageRelatedPackageSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackageRelatedPackages.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.FromPackageID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.FromPackageID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ToPackageID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ToPackageID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsPackageRelatedPackageSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_package_related_packages")...) +} + +func (s LocationsPackageRelatedPackageSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 3) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.FromPackageID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "from_package_id")...), + mysql.Arg(s.FromPackageID), + }}) + } + + if s.ToPackageID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "to_package_id")...), + mysql.Arg(s.ToPackageID), + }}) + } + + return exprs +} + +// FindLocationsPackageRelatedPackage retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsPackageRelatedPackage(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsPackageRelatedPackage, error) { + if len(cols) == 0 { + return LocationsPackageRelatedPackages.Query( + sm.Where(LocationsPackageRelatedPackages.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsPackageRelatedPackages.Query( + sm.Where(LocationsPackageRelatedPackages.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsPackageRelatedPackages.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsPackageRelatedPackageExists checks the presence of a single record by primary key +func LocationsPackageRelatedPackageExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsPackageRelatedPackages.Query( + sm.Where(LocationsPackageRelatedPackages.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsPackageRelatedPackage is retrieved from the database +func (o *LocationsPackageRelatedPackage) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPackageRelatedPackages.AfterSelectHooks.RunHooks(ctx, exec, LocationsPackageRelatedPackageSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsPackageRelatedPackages.AfterInsertHooks.RunHooks(ctx, exec, LocationsPackageRelatedPackageSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsPackageRelatedPackages.AfterUpdateHooks.RunHooks(ctx, exec, LocationsPackageRelatedPackageSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsPackageRelatedPackages.AfterDeleteHooks.RunHooks(ctx, exec, LocationsPackageRelatedPackageSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsPackageRelatedPackage +func (o *LocationsPackageRelatedPackage) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsPackageRelatedPackage) pkEQ() dialect.Expression { + return mysql.Quote("locations_package_related_packages", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsPackageRelatedPackage +func (o *LocationsPackageRelatedPackage) Update(ctx context.Context, exec bob.Executor, s *LocationsPackageRelatedPackageSetter) error { + _, err := LocationsPackageRelatedPackages.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsPackageRelatedPackage record with an executor +func (o *LocationsPackageRelatedPackage) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsPackageRelatedPackages.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsPackageRelatedPackage using the executor +func (o *LocationsPackageRelatedPackage) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsPackageRelatedPackages.Query( + sm.Where(LocationsPackageRelatedPackages.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsPackageRelatedPackageSlice is retrieved from the database +func (o LocationsPackageRelatedPackageSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPackageRelatedPackages.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsPackageRelatedPackages.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsPackageRelatedPackages.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsPackageRelatedPackages.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsPackageRelatedPackageSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_package_related_packages", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsPackageRelatedPackageSlice) copyMatchingRows(from ...*LocationsPackageRelatedPackage) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsPackageRelatedPackageSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackageRelatedPackages.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPackageRelatedPackage: + o.copyMatchingRows(retrieved) + case []*LocationsPackageRelatedPackage: + o.copyMatchingRows(retrieved...) + case LocationsPackageRelatedPackageSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPackageRelatedPackage or a slice of LocationsPackageRelatedPackage + // then run the AfterUpdateHooks on the slice + _, err = LocationsPackageRelatedPackages.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsPackageRelatedPackageSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackageRelatedPackages.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPackageRelatedPackage: + o.copyMatchingRows(retrieved) + case []*LocationsPackageRelatedPackage: + o.copyMatchingRows(retrieved...) + case LocationsPackageRelatedPackageSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPackageRelatedPackage or a slice of LocationsPackageRelatedPackage + // then run the AfterDeleteHooks on the slice + _, err = LocationsPackageRelatedPackages.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsPackageRelatedPackageSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsPackageRelatedPackageSetter) error { + _, err := LocationsPackageRelatedPackages.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsPackageRelatedPackageSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsPackageRelatedPackages.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsPackageRelatedPackageSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsPackageRelatedPackages.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// FromPackageLocationsPackage starts a query for related objects on locations_package +func (o *LocationsPackageRelatedPackage) FromPackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.ID.EQ(mysql.Arg(o.FromPackageID))), + )...) +} + +func (os LocationsPackageRelatedPackageSlice) FromPackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.FromPackageID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// ToPackageLocationsPackage starts a query for related objects on locations_package +func (o *LocationsPackageRelatedPackage) ToPackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.ID.EQ(mysql.Arg(o.ToPackageID))), + )...) +} + +func (os LocationsPackageRelatedPackageSlice) ToPackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.ToPackageID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsPackageRelatedPackageFromPackageLocationsPackage0(ctx context.Context, exec bob.Executor, count int, locationsPackageRelatedPackage0 *LocationsPackageRelatedPackage, locationsPackage1 *LocationsPackage) (*LocationsPackageRelatedPackage, error) { + setter := &LocationsPackageRelatedPackageSetter{ + FromPackageID: omit.From(locationsPackage1.ID), + } + + err := locationsPackageRelatedPackage0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackageRelatedPackageFromPackageLocationsPackage0: %w", err) + } + + return locationsPackageRelatedPackage0, nil +} + +func (locationsPackageRelatedPackage0 *LocationsPackageRelatedPackage) InsertFromPackageLocationsPackage(ctx context.Context, exec bob.Executor, related *LocationsPackageSetter) error { + var err error + + locationsPackage1, err := LocationsPackages.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPackageRelatedPackageFromPackageLocationsPackage0(ctx, exec, 1, locationsPackageRelatedPackage0, locationsPackage1) + if err != nil { + return err + } + + locationsPackageRelatedPackage0.R.FromPackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.FromPackageLocationsPackageRelatedPackages = append(locationsPackage1.R.FromPackageLocationsPackageRelatedPackages, locationsPackageRelatedPackage0) + + return nil +} + +func (locationsPackageRelatedPackage0 *LocationsPackageRelatedPackage) AttachFromPackageLocationsPackage(ctx context.Context, exec bob.Executor, locationsPackage1 *LocationsPackage) error { + var err error + + _, err = attachLocationsPackageRelatedPackageFromPackageLocationsPackage0(ctx, exec, 1, locationsPackageRelatedPackage0, locationsPackage1) + if err != nil { + return err + } + + locationsPackageRelatedPackage0.R.FromPackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.FromPackageLocationsPackageRelatedPackages = append(locationsPackage1.R.FromPackageLocationsPackageRelatedPackages, locationsPackageRelatedPackage0) + + return nil +} + +func attachLocationsPackageRelatedPackageToPackageLocationsPackage0(ctx context.Context, exec bob.Executor, count int, locationsPackageRelatedPackage0 *LocationsPackageRelatedPackage, locationsPackage1 *LocationsPackage) (*LocationsPackageRelatedPackage, error) { + setter := &LocationsPackageRelatedPackageSetter{ + ToPackageID: omit.From(locationsPackage1.ID), + } + + err := locationsPackageRelatedPackage0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackageRelatedPackageToPackageLocationsPackage0: %w", err) + } + + return locationsPackageRelatedPackage0, nil +} + +func (locationsPackageRelatedPackage0 *LocationsPackageRelatedPackage) InsertToPackageLocationsPackage(ctx context.Context, exec bob.Executor, related *LocationsPackageSetter) error { + var err error + + locationsPackage1, err := LocationsPackages.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPackageRelatedPackageToPackageLocationsPackage0(ctx, exec, 1, locationsPackageRelatedPackage0, locationsPackage1) + if err != nil { + return err + } + + locationsPackageRelatedPackage0.R.ToPackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.ToPackageLocationsPackageRelatedPackages = append(locationsPackage1.R.ToPackageLocationsPackageRelatedPackages, locationsPackageRelatedPackage0) + + return nil +} + +func (locationsPackageRelatedPackage0 *LocationsPackageRelatedPackage) AttachToPackageLocationsPackage(ctx context.Context, exec bob.Executor, locationsPackage1 *LocationsPackage) error { + var err error + + _, err = attachLocationsPackageRelatedPackageToPackageLocationsPackage0(ctx, exec, 1, locationsPackageRelatedPackage0, locationsPackage1) + if err != nil { + return err + } + + locationsPackageRelatedPackage0.R.ToPackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.ToPackageLocationsPackageRelatedPackages = append(locationsPackage1.R.ToPackageLocationsPackageRelatedPackages, locationsPackageRelatedPackage0) + + return nil +} + +type locationsPackageRelatedPackageWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + FromPackageID mysql.WhereMod[Q, int32] + ToPackageID mysql.WhereMod[Q, int32] +} + +func (locationsPackageRelatedPackageWhere[Q]) AliasedAs(alias string) locationsPackageRelatedPackageWhere[Q] { + return buildLocationsPackageRelatedPackageWhere[Q](buildLocationsPackageRelatedPackageColumns(alias)) +} + +func buildLocationsPackageRelatedPackageWhere[Q mysql.Filterable](cols locationsPackageRelatedPackageColumns) locationsPackageRelatedPackageWhere[Q] { + return locationsPackageRelatedPackageWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + FromPackageID: mysql.Where[Q, int32](cols.FromPackageID), + ToPackageID: mysql.Where[Q, int32](cols.ToPackageID), + } +} + +func (o *LocationsPackageRelatedPackage) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "FromPackageLocationsPackage": + rel, ok := retrieved.(*LocationsPackage) + if !ok { + return fmt.Errorf("locationsPackageRelatedPackage cannot load %T as %q", retrieved, name) + } + + o.R.FromPackageLocationsPackage = rel + + if rel != nil { + rel.R.FromPackageLocationsPackageRelatedPackages = LocationsPackageRelatedPackageSlice{o} + } + return nil + case "ToPackageLocationsPackage": + rel, ok := retrieved.(*LocationsPackage) + if !ok { + return fmt.Errorf("locationsPackageRelatedPackage cannot load %T as %q", retrieved, name) + } + + o.R.ToPackageLocationsPackage = rel + + if rel != nil { + rel.R.ToPackageLocationsPackageRelatedPackages = LocationsPackageRelatedPackageSlice{o} + } + return nil + default: + return fmt.Errorf("locationsPackageRelatedPackage has no relationship %q", name) + } +} + +type locationsPackageRelatedPackagePreloader struct { + FromPackageLocationsPackage func(...mysql.PreloadOption) mysql.Preloader + ToPackageLocationsPackage func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsPackageRelatedPackagePreloader() locationsPackageRelatedPackagePreloader { + return locationsPackageRelatedPackagePreloader{ + FromPackageLocationsPackage: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPackage, LocationsPackageSlice](mysql.PreloadRel{ + Name: "FromPackageLocationsPackage", + Sides: []mysql.PreloadSide{ + { + From: LocationsPackageRelatedPackages, + To: LocationsPackages, + FromColumns: []string{"from_package_id"}, + ToColumns: []string{"id"}, + }, + }, + }, LocationsPackages.Columns.Names(), opts...) + }, + ToPackageLocationsPackage: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPackage, LocationsPackageSlice](mysql.PreloadRel{ + Name: "ToPackageLocationsPackage", + Sides: []mysql.PreloadSide{ + { + From: LocationsPackageRelatedPackages, + To: LocationsPackages, + FromColumns: []string{"to_package_id"}, + ToColumns: []string{"id"}, + }, + }, + }, LocationsPackages.Columns.Names(), opts...) + }, + } +} + +type locationsPackageRelatedPackageThenLoader[Q orm.Loadable] struct { + FromPackageLocationsPackage func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + ToPackageLocationsPackage func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsPackageRelatedPackageThenLoader[Q orm.Loadable]() locationsPackageRelatedPackageThenLoader[Q] { + type FromPackageLocationsPackageLoadInterface interface { + LoadFromPackageLocationsPackage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type ToPackageLocationsPackageLoadInterface interface { + LoadToPackageLocationsPackage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsPackageRelatedPackageThenLoader[Q]{ + FromPackageLocationsPackage: thenLoadBuilder[Q]( + "FromPackageLocationsPackage", + func(ctx context.Context, exec bob.Executor, retrieved FromPackageLocationsPackageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadFromPackageLocationsPackage(ctx, exec, mods...) + }, + ), + ToPackageLocationsPackage: thenLoadBuilder[Q]( + "ToPackageLocationsPackage", + func(ctx context.Context, exec bob.Executor, retrieved ToPackageLocationsPackageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadToPackageLocationsPackage(ctx, exec, mods...) + }, + ), + } +} + +// LoadFromPackageLocationsPackage loads the locationsPackageRelatedPackage's FromPackageLocationsPackage into the .R struct +func (o *LocationsPackageRelatedPackage) LoadFromPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.FromPackageLocationsPackage = nil + + related, err := o.FromPackageLocationsPackage(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.FromPackageLocationsPackageRelatedPackages = LocationsPackageRelatedPackageSlice{o} + + o.R.FromPackageLocationsPackage = related + return nil +} + +// LoadFromPackageLocationsPackage loads the locationsPackageRelatedPackage's FromPackageLocationsPackage into the .R struct +func (os LocationsPackageRelatedPackageSlice) LoadFromPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.FromPackageLocationsPackage(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !(o.FromPackageID == rel.ID) { + continue + } + + rel.R.FromPackageLocationsPackageRelatedPackages = append(rel.R.FromPackageLocationsPackageRelatedPackages, o) + + o.R.FromPackageLocationsPackage = rel + break + } + } + + return nil +} + +// LoadToPackageLocationsPackage loads the locationsPackageRelatedPackage's ToPackageLocationsPackage into the .R struct +func (o *LocationsPackageRelatedPackage) LoadToPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.ToPackageLocationsPackage = nil + + related, err := o.ToPackageLocationsPackage(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.ToPackageLocationsPackageRelatedPackages = LocationsPackageRelatedPackageSlice{o} + + o.R.ToPackageLocationsPackage = related + return nil +} + +// LoadToPackageLocationsPackage loads the locationsPackageRelatedPackage's ToPackageLocationsPackage into the .R struct +func (os LocationsPackageRelatedPackageSlice) LoadToPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.ToPackageLocationsPackage(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !(o.ToPackageID == rel.ID) { + continue + } + + rel.R.ToPackageLocationsPackageRelatedPackages = append(rel.R.ToPackageLocationsPackageRelatedPackages, o) + + o.R.ToPackageLocationsPackage = rel + break + } + } + + return nil +} + +type locationsPackageRelatedPackageJoins[Q dialect.Joinable] struct { + typ string + FromPackageLocationsPackage modAs[Q, locationsPackageColumns] + ToPackageLocationsPackage modAs[Q, locationsPackageColumns] +} + +func (j locationsPackageRelatedPackageJoins[Q]) aliasedAs(alias string) locationsPackageRelatedPackageJoins[Q] { + return buildLocationsPackageRelatedPackageJoins[Q](buildLocationsPackageRelatedPackageColumns(alias), j.typ) +} + +func buildLocationsPackageRelatedPackageJoins[Q dialect.Joinable](cols locationsPackageRelatedPackageColumns, typ string) locationsPackageRelatedPackageJoins[Q] { + return locationsPackageRelatedPackageJoins[Q]{ + typ: typ, + FromPackageLocationsPackage: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.ID.EQ(cols.FromPackageID), + )) + } + + return mods + }, + }, + ToPackageLocationsPackage: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.ID.EQ(cols.ToPackageID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_packagedownloadtask.bob.go b/database/storage_service/models/locations_packagedownloadtask.bob.go new file mode 100644 index 0000000..3e221d5 --- /dev/null +++ b/database/storage_service/models/locations_packagedownloadtask.bob.go @@ -0,0 +1,879 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsPackagedownloadtask is an object representing the database table. +type LocationsPackagedownloadtask struct { + ID int32 `db:"id,pk,autoincr" ` + UUID string `db:"uuid" ` + DownloadsAttempted int32 `db:"downloads_attempted" ` + DownloadsCompleted int32 `db:"downloads_completed" ` + DownloadCompletionTime null.Val[time.Time] `db:"download_completion_time" ` + PackageID string `db:"package_id" ` + + R locationsPackagedownloadtaskR `db:"-" ` +} + +// LocationsPackagedownloadtaskSlice is an alias for a slice of pointers to LocationsPackagedownloadtask. +// This should almost always be used instead of []*LocationsPackagedownloadtask. +type LocationsPackagedownloadtaskSlice []*LocationsPackagedownloadtask + +// LocationsPackagedownloadtasks contains methods to work with the locations_packagedownloadtask table +var LocationsPackagedownloadtasks = mysql.NewTablex[*LocationsPackagedownloadtask, LocationsPackagedownloadtaskSlice, *LocationsPackagedownloadtaskSetter]("locations_packagedownloadtask", buildLocationsPackagedownloadtaskColumns("locations_packagedownloadtask"), []string{"id"}, []string{"uuid"}) + +// LocationsPackagedownloadtasksQuery is a query on the locations_packagedownloadtask table +type LocationsPackagedownloadtasksQuery = *mysql.ViewQuery[*LocationsPackagedownloadtask, LocationsPackagedownloadtaskSlice] + +// locationsPackagedownloadtaskR is where relationships are stored. +type locationsPackagedownloadtaskR struct { + PackageLocationsPackage *LocationsPackage // locations_packagedow_package_id_488c7751_fk_locations + UUIDLocationsPackagedownloadtaskfiles LocationsPackagedownloadtaskfileSlice // locations_packagedow_task_id_a112c9ea_fk_locations +} + +func buildLocationsPackagedownloadtaskColumns(alias string) locationsPackagedownloadtaskColumns { + return locationsPackagedownloadtaskColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "uuid", "downloads_attempted", "downloads_completed", "download_completion_time", "package_id", + ).WithParent("locations_packagedownloadtask"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UUID: mysql.Quote(alias, "uuid"), + DownloadsAttempted: mysql.Quote(alias, "downloads_attempted"), + DownloadsCompleted: mysql.Quote(alias, "downloads_completed"), + DownloadCompletionTime: mysql.Quote(alias, "download_completion_time"), + PackageID: mysql.Quote(alias, "package_id"), + } +} + +type locationsPackagedownloadtaskColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UUID mysql.Expression + DownloadsAttempted mysql.Expression + DownloadsCompleted mysql.Expression + DownloadCompletionTime mysql.Expression + PackageID mysql.Expression +} + +func (c locationsPackagedownloadtaskColumns) Alias() string { + return c.tableAlias +} + +func (locationsPackagedownloadtaskColumns) AliasedAs(alias string) locationsPackagedownloadtaskColumns { + return buildLocationsPackagedownloadtaskColumns(alias) +} + +// LocationsPackagedownloadtaskSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsPackagedownloadtaskSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UUID omit.Val[string] `db:"uuid" ` + DownloadsAttempted omit.Val[int32] `db:"downloads_attempted" ` + DownloadsCompleted omit.Val[int32] `db:"downloads_completed" ` + DownloadCompletionTime omitnull.Val[time.Time] `db:"download_completion_time" ` + PackageID omit.Val[string] `db:"package_id" ` +} + +func (s LocationsPackagedownloadtaskSetter) SetColumns() []string { + vals := make([]string, 0, 6) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UUID.IsValue() { + vals = append(vals, "uuid") + } + if s.DownloadsAttempted.IsValue() { + vals = append(vals, "downloads_attempted") + } + if s.DownloadsCompleted.IsValue() { + vals = append(vals, "downloads_completed") + } + if !s.DownloadCompletionTime.IsUnset() { + vals = append(vals, "download_completion_time") + } + if s.PackageID.IsValue() { + vals = append(vals, "package_id") + } + return vals +} + +func (s LocationsPackagedownloadtaskSetter) Overwrite(t *LocationsPackagedownloadtask) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UUID.IsValue() { + t.UUID = s.UUID.MustGet() + } + if s.DownloadsAttempted.IsValue() { + t.DownloadsAttempted = s.DownloadsAttempted.MustGet() + } + if s.DownloadsCompleted.IsValue() { + t.DownloadsCompleted = s.DownloadsCompleted.MustGet() + } + if !s.DownloadCompletionTime.IsUnset() { + t.DownloadCompletionTime = s.DownloadCompletionTime.MustGetNull() + } + if s.PackageID.IsValue() { + t.PackageID = s.PackageID.MustGet() + } +} + +func (s *LocationsPackagedownloadtaskSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackagedownloadtasks.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UUID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UUID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DownloadsAttempted.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DownloadsAttempted.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.DownloadsCompleted.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DownloadsCompleted.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.DownloadCompletionTime.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.DownloadCompletionTime.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.PackageID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.PackageID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsPackagedownloadtaskSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_packagedownloadtask")...) +} + +func (s LocationsPackagedownloadtaskSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 6) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UUID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uuid")...), + mysql.Arg(s.UUID), + }}) + } + + if s.DownloadsAttempted.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "downloads_attempted")...), + mysql.Arg(s.DownloadsAttempted), + }}) + } + + if s.DownloadsCompleted.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "downloads_completed")...), + mysql.Arg(s.DownloadsCompleted), + }}) + } + + if !s.DownloadCompletionTime.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "download_completion_time")...), + mysql.Arg(s.DownloadCompletionTime), + }}) + } + + if s.PackageID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "package_id")...), + mysql.Arg(s.PackageID), + }}) + } + + return exprs +} + +// FindLocationsPackagedownloadtask retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsPackagedownloadtask(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsPackagedownloadtask, error) { + if len(cols) == 0 { + return LocationsPackagedownloadtasks.Query( + sm.Where(LocationsPackagedownloadtasks.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsPackagedownloadtasks.Query( + sm.Where(LocationsPackagedownloadtasks.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsPackagedownloadtasks.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsPackagedownloadtaskExists checks the presence of a single record by primary key +func LocationsPackagedownloadtaskExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsPackagedownloadtasks.Query( + sm.Where(LocationsPackagedownloadtasks.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsPackagedownloadtask is retrieved from the database +func (o *LocationsPackagedownloadtask) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPackagedownloadtasks.AfterSelectHooks.RunHooks(ctx, exec, LocationsPackagedownloadtaskSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsPackagedownloadtasks.AfterInsertHooks.RunHooks(ctx, exec, LocationsPackagedownloadtaskSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsPackagedownloadtasks.AfterUpdateHooks.RunHooks(ctx, exec, LocationsPackagedownloadtaskSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsPackagedownloadtasks.AfterDeleteHooks.RunHooks(ctx, exec, LocationsPackagedownloadtaskSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsPackagedownloadtask +func (o *LocationsPackagedownloadtask) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsPackagedownloadtask) pkEQ() dialect.Expression { + return mysql.Quote("locations_packagedownloadtask", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsPackagedownloadtask +func (o *LocationsPackagedownloadtask) Update(ctx context.Context, exec bob.Executor, s *LocationsPackagedownloadtaskSetter) error { + _, err := LocationsPackagedownloadtasks.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsPackagedownloadtask record with an executor +func (o *LocationsPackagedownloadtask) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsPackagedownloadtasks.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsPackagedownloadtask using the executor +func (o *LocationsPackagedownloadtask) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsPackagedownloadtasks.Query( + sm.Where(LocationsPackagedownloadtasks.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsPackagedownloadtaskSlice is retrieved from the database +func (o LocationsPackagedownloadtaskSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPackagedownloadtasks.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsPackagedownloadtasks.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsPackagedownloadtasks.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsPackagedownloadtasks.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsPackagedownloadtaskSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_packagedownloadtask", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsPackagedownloadtaskSlice) copyMatchingRows(from ...*LocationsPackagedownloadtask) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsPackagedownloadtaskSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackagedownloadtasks.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPackagedownloadtask: + o.copyMatchingRows(retrieved) + case []*LocationsPackagedownloadtask: + o.copyMatchingRows(retrieved...) + case LocationsPackagedownloadtaskSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPackagedownloadtask or a slice of LocationsPackagedownloadtask + // then run the AfterUpdateHooks on the slice + _, err = LocationsPackagedownloadtasks.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsPackagedownloadtaskSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackagedownloadtasks.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPackagedownloadtask: + o.copyMatchingRows(retrieved) + case []*LocationsPackagedownloadtask: + o.copyMatchingRows(retrieved...) + case LocationsPackagedownloadtaskSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPackagedownloadtask or a slice of LocationsPackagedownloadtask + // then run the AfterDeleteHooks on the slice + _, err = LocationsPackagedownloadtasks.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsPackagedownloadtaskSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsPackagedownloadtaskSetter) error { + _, err := LocationsPackagedownloadtasks.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsPackagedownloadtaskSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsPackagedownloadtasks.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsPackagedownloadtaskSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsPackagedownloadtasks.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// PackageLocationsPackage starts a query for related objects on locations_package +func (o *LocationsPackagedownloadtask) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.UUID.EQ(mysql.Arg(o.PackageID))), + )...) +} + +func (os LocationsPackagedownloadtaskSlice) PackageLocationsPackage(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.PackageID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +// UUIDLocationsPackagedownloadtaskfiles starts a query for related objects on locations_packagedownloadtaskfile +func (o *LocationsPackagedownloadtask) UUIDLocationsPackagedownloadtaskfiles(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagedownloadtaskfilesQuery { + return LocationsPackagedownloadtaskfiles.Query(append(mods, + sm.Where(LocationsPackagedownloadtaskfiles.Columns.TaskID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsPackagedownloadtaskSlice) UUIDLocationsPackagedownloadtaskfiles(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagedownloadtaskfilesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackagedownloadtaskfiles.Query(append(mods, + sm.Where(mysql.Group(LocationsPackagedownloadtaskfiles.Columns.TaskID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsPackagedownloadtaskPackageLocationsPackage0(ctx context.Context, exec bob.Executor, count int, locationsPackagedownloadtask0 *LocationsPackagedownloadtask, locationsPackage1 *LocationsPackage) (*LocationsPackagedownloadtask, error) { + setter := &LocationsPackagedownloadtaskSetter{ + PackageID: omit.From(locationsPackage1.UUID), + } + + err := locationsPackagedownloadtask0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackagedownloadtaskPackageLocationsPackage0: %w", err) + } + + return locationsPackagedownloadtask0, nil +} + +func (locationsPackagedownloadtask0 *LocationsPackagedownloadtask) InsertPackageLocationsPackage(ctx context.Context, exec bob.Executor, related *LocationsPackageSetter) error { + var err error + + locationsPackage1, err := LocationsPackages.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPackagedownloadtaskPackageLocationsPackage0(ctx, exec, 1, locationsPackagedownloadtask0, locationsPackage1) + if err != nil { + return err + } + + locationsPackagedownloadtask0.R.PackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.PackageLocationsPackagedownloadtasks = append(locationsPackage1.R.PackageLocationsPackagedownloadtasks, locationsPackagedownloadtask0) + + return nil +} + +func (locationsPackagedownloadtask0 *LocationsPackagedownloadtask) AttachPackageLocationsPackage(ctx context.Context, exec bob.Executor, locationsPackage1 *LocationsPackage) error { + var err error + + _, err = attachLocationsPackagedownloadtaskPackageLocationsPackage0(ctx, exec, 1, locationsPackagedownloadtask0, locationsPackage1) + if err != nil { + return err + } + + locationsPackagedownloadtask0.R.PackageLocationsPackage = locationsPackage1 + + locationsPackage1.R.PackageLocationsPackagedownloadtasks = append(locationsPackage1.R.PackageLocationsPackagedownloadtasks, locationsPackagedownloadtask0) + + return nil +} + +func insertLocationsPackagedownloadtaskUUIDLocationsPackagedownloadtaskfiles0(ctx context.Context, exec bob.Executor, locationsPackagedownloadtaskfiles1 []*LocationsPackagedownloadtaskfileSetter, locationsPackagedownloadtask0 *LocationsPackagedownloadtask) (LocationsPackagedownloadtaskfileSlice, error) { + for i := range locationsPackagedownloadtaskfiles1 { + locationsPackagedownloadtaskfiles1[i].TaskID = omit.From(locationsPackagedownloadtask0.UUID) + } + + ret, err := LocationsPackagedownloadtaskfiles.Insert(bob.ToMods(locationsPackagedownloadtaskfiles1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPackagedownloadtaskUUIDLocationsPackagedownloadtaskfiles0: %w", err) + } + + return ret, nil +} + +func attachLocationsPackagedownloadtaskUUIDLocationsPackagedownloadtaskfiles0(ctx context.Context, exec bob.Executor, count int, locationsPackagedownloadtaskfiles1 LocationsPackagedownloadtaskfileSlice, locationsPackagedownloadtask0 *LocationsPackagedownloadtask) (LocationsPackagedownloadtaskfileSlice, error) { + setter := &LocationsPackagedownloadtaskfileSetter{ + TaskID: omit.From(locationsPackagedownloadtask0.UUID), + } + + err := locationsPackagedownloadtaskfiles1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackagedownloadtaskUUIDLocationsPackagedownloadtaskfiles0: %w", err) + } + + return locationsPackagedownloadtaskfiles1, nil +} + +func (locationsPackagedownloadtask0 *LocationsPackagedownloadtask) InsertUUIDLocationsPackagedownloadtaskfiles(ctx context.Context, exec bob.Executor, related ...*LocationsPackagedownloadtaskfileSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsPackagedownloadtaskfiles1, err := insertLocationsPackagedownloadtaskUUIDLocationsPackagedownloadtaskfiles0(ctx, exec, related, locationsPackagedownloadtask0) + if err != nil { + return err + } + + locationsPackagedownloadtask0.R.UUIDLocationsPackagedownloadtaskfiles = append(locationsPackagedownloadtask0.R.UUIDLocationsPackagedownloadtaskfiles, locationsPackagedownloadtaskfiles1...) + + for _, rel := range locationsPackagedownloadtaskfiles1 { + rel.R.TaskLocationsPackagedownloadtask = locationsPackagedownloadtask0 + } + return nil +} + +func (locationsPackagedownloadtask0 *LocationsPackagedownloadtask) AttachUUIDLocationsPackagedownloadtaskfiles(ctx context.Context, exec bob.Executor, related ...*LocationsPackagedownloadtaskfile) error { + if len(related) == 0 { + return nil + } + + var err error + locationsPackagedownloadtaskfiles1 := LocationsPackagedownloadtaskfileSlice(related) + + _, err = attachLocationsPackagedownloadtaskUUIDLocationsPackagedownloadtaskfiles0(ctx, exec, len(related), locationsPackagedownloadtaskfiles1, locationsPackagedownloadtask0) + if err != nil { + return err + } + + locationsPackagedownloadtask0.R.UUIDLocationsPackagedownloadtaskfiles = append(locationsPackagedownloadtask0.R.UUIDLocationsPackagedownloadtaskfiles, locationsPackagedownloadtaskfiles1...) + + for _, rel := range related { + rel.R.TaskLocationsPackagedownloadtask = locationsPackagedownloadtask0 + } + + return nil +} + +type locationsPackagedownloadtaskWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UUID mysql.WhereMod[Q, string] + DownloadsAttempted mysql.WhereMod[Q, int32] + DownloadsCompleted mysql.WhereMod[Q, int32] + DownloadCompletionTime mysql.WhereNullMod[Q, time.Time] + PackageID mysql.WhereMod[Q, string] +} + +func (locationsPackagedownloadtaskWhere[Q]) AliasedAs(alias string) locationsPackagedownloadtaskWhere[Q] { + return buildLocationsPackagedownloadtaskWhere[Q](buildLocationsPackagedownloadtaskColumns(alias)) +} + +func buildLocationsPackagedownloadtaskWhere[Q mysql.Filterable](cols locationsPackagedownloadtaskColumns) locationsPackagedownloadtaskWhere[Q] { + return locationsPackagedownloadtaskWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UUID: mysql.Where[Q, string](cols.UUID), + DownloadsAttempted: mysql.Where[Q, int32](cols.DownloadsAttempted), + DownloadsCompleted: mysql.Where[Q, int32](cols.DownloadsCompleted), + DownloadCompletionTime: mysql.WhereNull[Q, time.Time](cols.DownloadCompletionTime), + PackageID: mysql.Where[Q, string](cols.PackageID), + } +} + +func (o *LocationsPackagedownloadtask) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "PackageLocationsPackage": + rel, ok := retrieved.(*LocationsPackage) + if !ok { + return fmt.Errorf("locationsPackagedownloadtask cannot load %T as %q", retrieved, name) + } + + o.R.PackageLocationsPackage = rel + + if rel != nil { + rel.R.PackageLocationsPackagedownloadtasks = LocationsPackagedownloadtaskSlice{o} + } + return nil + case "UUIDLocationsPackagedownloadtaskfiles": + rels, ok := retrieved.(LocationsPackagedownloadtaskfileSlice) + if !ok { + return fmt.Errorf("locationsPackagedownloadtask cannot load %T as %q", retrieved, name) + } + + o.R.UUIDLocationsPackagedownloadtaskfiles = rels + + for _, rel := range rels { + if rel != nil { + rel.R.TaskLocationsPackagedownloadtask = o + } + } + return nil + default: + return fmt.Errorf("locationsPackagedownloadtask has no relationship %q", name) + } +} + +type locationsPackagedownloadtaskPreloader struct { + PackageLocationsPackage func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsPackagedownloadtaskPreloader() locationsPackagedownloadtaskPreloader { + return locationsPackagedownloadtaskPreloader{ + PackageLocationsPackage: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPackage, LocationsPackageSlice](mysql.PreloadRel{ + Name: "PackageLocationsPackage", + Sides: []mysql.PreloadSide{ + { + From: LocationsPackagedownloadtasks, + To: LocationsPackages, + FromColumns: []string{"package_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsPackages.Columns.Names(), opts...) + }, + } +} + +type locationsPackagedownloadtaskThenLoader[Q orm.Loadable] struct { + PackageLocationsPackage func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + UUIDLocationsPackagedownloadtaskfiles func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsPackagedownloadtaskThenLoader[Q orm.Loadable]() locationsPackagedownloadtaskThenLoader[Q] { + type PackageLocationsPackageLoadInterface interface { + LoadPackageLocationsPackage(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type UUIDLocationsPackagedownloadtaskfilesLoadInterface interface { + LoadUUIDLocationsPackagedownloadtaskfiles(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsPackagedownloadtaskThenLoader[Q]{ + PackageLocationsPackage: thenLoadBuilder[Q]( + "PackageLocationsPackage", + func(ctx context.Context, exec bob.Executor, retrieved PackageLocationsPackageLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPackageLocationsPackage(ctx, exec, mods...) + }, + ), + UUIDLocationsPackagedownloadtaskfiles: thenLoadBuilder[Q]( + "UUIDLocationsPackagedownloadtaskfiles", + func(ctx context.Context, exec bob.Executor, retrieved UUIDLocationsPackagedownloadtaskfilesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUUIDLocationsPackagedownloadtaskfiles(ctx, exec, mods...) + }, + ), + } +} + +// LoadPackageLocationsPackage loads the locationsPackagedownloadtask's PackageLocationsPackage into the .R struct +func (o *LocationsPackagedownloadtask) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PackageLocationsPackage = nil + + related, err := o.PackageLocationsPackage(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.PackageLocationsPackagedownloadtasks = LocationsPackagedownloadtaskSlice{o} + + o.R.PackageLocationsPackage = related + return nil +} + +// LoadPackageLocationsPackage loads the locationsPackagedownloadtask's PackageLocationsPackage into the .R struct +func (os LocationsPackagedownloadtaskSlice) LoadPackageLocationsPackage(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.PackageLocationsPackage(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !(o.PackageID == rel.UUID) { + continue + } + + rel.R.PackageLocationsPackagedownloadtasks = append(rel.R.PackageLocationsPackagedownloadtasks, o) + + o.R.PackageLocationsPackage = rel + break + } + } + + return nil +} + +// LoadUUIDLocationsPackagedownloadtaskfiles loads the locationsPackagedownloadtask's UUIDLocationsPackagedownloadtaskfiles into the .R struct +func (o *LocationsPackagedownloadtask) LoadUUIDLocationsPackagedownloadtaskfiles(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UUIDLocationsPackagedownloadtaskfiles = nil + + related, err := o.UUIDLocationsPackagedownloadtaskfiles(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.TaskLocationsPackagedownloadtask = o + } + + o.R.UUIDLocationsPackagedownloadtaskfiles = related + return nil +} + +// LoadUUIDLocationsPackagedownloadtaskfiles loads the locationsPackagedownloadtask's UUIDLocationsPackagedownloadtaskfiles into the .R struct +func (os LocationsPackagedownloadtaskSlice) LoadUUIDLocationsPackagedownloadtaskfiles(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackagedownloadtaskfiles, err := os.UUIDLocationsPackagedownloadtaskfiles(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.UUIDLocationsPackagedownloadtaskfiles = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackagedownloadtaskfiles { + + if !(o.UUID == rel.TaskID) { + continue + } + + rel.R.TaskLocationsPackagedownloadtask = o + + o.R.UUIDLocationsPackagedownloadtaskfiles = append(o.R.UUIDLocationsPackagedownloadtaskfiles, rel) + } + } + + return nil +} + +type locationsPackagedownloadtaskJoins[Q dialect.Joinable] struct { + typ string + PackageLocationsPackage modAs[Q, locationsPackageColumns] + UUIDLocationsPackagedownloadtaskfiles modAs[Q, locationsPackagedownloadtaskfileColumns] +} + +func (j locationsPackagedownloadtaskJoins[Q]) aliasedAs(alias string) locationsPackagedownloadtaskJoins[Q] { + return buildLocationsPackagedownloadtaskJoins[Q](buildLocationsPackagedownloadtaskColumns(alias), j.typ) +} + +func buildLocationsPackagedownloadtaskJoins[Q dialect.Joinable](cols locationsPackagedownloadtaskColumns, typ string) locationsPackagedownloadtaskJoins[Q] { + return locationsPackagedownloadtaskJoins[Q]{ + typ: typ, + PackageLocationsPackage: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.UUID.EQ(cols.PackageID), + )) + } + + return mods + }, + }, + UUIDLocationsPackagedownloadtaskfiles: modAs[Q, locationsPackagedownloadtaskfileColumns]{ + c: LocationsPackagedownloadtaskfiles.Columns, + f: func(to locationsPackagedownloadtaskfileColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackagedownloadtaskfiles.Name().As(to.Alias())).On( + to.TaskID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_packagedownloadtaskfile.bob.go b/database/storage_service/models/locations_packagedownloadtaskfile.bob.go new file mode 100644 index 0000000..79cc2ba --- /dev/null +++ b/database/storage_service/models/locations_packagedownloadtaskfile.bob.go @@ -0,0 +1,712 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsPackagedownloadtaskfile is an object representing the database table. +type LocationsPackagedownloadtaskfile struct { + ID int32 `db:"id,pk,autoincr" ` + UUID string `db:"uuid" ` + Filename string `db:"filename" ` + URL string `db:"url" ` + Completed bool `db:"completed" ` + Failed bool `db:"failed" ` + TaskID string `db:"task_id" ` + + R locationsPackagedownloadtaskfileR `db:"-" ` +} + +// LocationsPackagedownloadtaskfileSlice is an alias for a slice of pointers to LocationsPackagedownloadtaskfile. +// This should almost always be used instead of []*LocationsPackagedownloadtaskfile. +type LocationsPackagedownloadtaskfileSlice []*LocationsPackagedownloadtaskfile + +// LocationsPackagedownloadtaskfiles contains methods to work with the locations_packagedownloadtaskfile table +var LocationsPackagedownloadtaskfiles = mysql.NewTablex[*LocationsPackagedownloadtaskfile, LocationsPackagedownloadtaskfileSlice, *LocationsPackagedownloadtaskfileSetter]("locations_packagedownloadtaskfile", buildLocationsPackagedownloadtaskfileColumns("locations_packagedownloadtaskfile"), []string{"id"}, []string{"uuid"}) + +// LocationsPackagedownloadtaskfilesQuery is a query on the locations_packagedownloadtaskfile table +type LocationsPackagedownloadtaskfilesQuery = *mysql.ViewQuery[*LocationsPackagedownloadtaskfile, LocationsPackagedownloadtaskfileSlice] + +// locationsPackagedownloadtaskfileR is where relationships are stored. +type locationsPackagedownloadtaskfileR struct { + TaskLocationsPackagedownloadtask *LocationsPackagedownloadtask // locations_packagedow_task_id_a112c9ea_fk_locations +} + +func buildLocationsPackagedownloadtaskfileColumns(alias string) locationsPackagedownloadtaskfileColumns { + return locationsPackagedownloadtaskfileColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "uuid", "filename", "url", "completed", "failed", "task_id", + ).WithParent("locations_packagedownloadtaskfile"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UUID: mysql.Quote(alias, "uuid"), + Filename: mysql.Quote(alias, "filename"), + URL: mysql.Quote(alias, "url"), + Completed: mysql.Quote(alias, "completed"), + Failed: mysql.Quote(alias, "failed"), + TaskID: mysql.Quote(alias, "task_id"), + } +} + +type locationsPackagedownloadtaskfileColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UUID mysql.Expression + Filename mysql.Expression + URL mysql.Expression + Completed mysql.Expression + Failed mysql.Expression + TaskID mysql.Expression +} + +func (c locationsPackagedownloadtaskfileColumns) Alias() string { + return c.tableAlias +} + +func (locationsPackagedownloadtaskfileColumns) AliasedAs(alias string) locationsPackagedownloadtaskfileColumns { + return buildLocationsPackagedownloadtaskfileColumns(alias) +} + +// LocationsPackagedownloadtaskfileSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsPackagedownloadtaskfileSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UUID omit.Val[string] `db:"uuid" ` + Filename omit.Val[string] `db:"filename" ` + URL omit.Val[string] `db:"url" ` + Completed omit.Val[bool] `db:"completed" ` + Failed omit.Val[bool] `db:"failed" ` + TaskID omit.Val[string] `db:"task_id" ` +} + +func (s LocationsPackagedownloadtaskfileSetter) SetColumns() []string { + vals := make([]string, 0, 7) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UUID.IsValue() { + vals = append(vals, "uuid") + } + if s.Filename.IsValue() { + vals = append(vals, "filename") + } + if s.URL.IsValue() { + vals = append(vals, "url") + } + if s.Completed.IsValue() { + vals = append(vals, "completed") + } + if s.Failed.IsValue() { + vals = append(vals, "failed") + } + if s.TaskID.IsValue() { + vals = append(vals, "task_id") + } + return vals +} + +func (s LocationsPackagedownloadtaskfileSetter) Overwrite(t *LocationsPackagedownloadtaskfile) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UUID.IsValue() { + t.UUID = s.UUID.MustGet() + } + if s.Filename.IsValue() { + t.Filename = s.Filename.MustGet() + } + if s.URL.IsValue() { + t.URL = s.URL.MustGet() + } + if s.Completed.IsValue() { + t.Completed = s.Completed.MustGet() + } + if s.Failed.IsValue() { + t.Failed = s.Failed.MustGet() + } + if s.TaskID.IsValue() { + t.TaskID = s.TaskID.MustGet() + } +} + +func (s *LocationsPackagedownloadtaskfileSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackagedownloadtaskfiles.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UUID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UUID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Filename.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Filename.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.URL.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.URL.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Completed.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Completed.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Failed.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Failed.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.TaskID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.TaskID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsPackagedownloadtaskfileSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_packagedownloadtaskfile")...) +} + +func (s LocationsPackagedownloadtaskfileSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 7) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UUID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uuid")...), + mysql.Arg(s.UUID), + }}) + } + + if s.Filename.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "filename")...), + mysql.Arg(s.Filename), + }}) + } + + if s.URL.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "url")...), + mysql.Arg(s.URL), + }}) + } + + if s.Completed.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "completed")...), + mysql.Arg(s.Completed), + }}) + } + + if s.Failed.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "failed")...), + mysql.Arg(s.Failed), + }}) + } + + if s.TaskID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "task_id")...), + mysql.Arg(s.TaskID), + }}) + } + + return exprs +} + +// FindLocationsPackagedownloadtaskfile retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsPackagedownloadtaskfile(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsPackagedownloadtaskfile, error) { + if len(cols) == 0 { + return LocationsPackagedownloadtaskfiles.Query( + sm.Where(LocationsPackagedownloadtaskfiles.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsPackagedownloadtaskfiles.Query( + sm.Where(LocationsPackagedownloadtaskfiles.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsPackagedownloadtaskfiles.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsPackagedownloadtaskfileExists checks the presence of a single record by primary key +func LocationsPackagedownloadtaskfileExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsPackagedownloadtaskfiles.Query( + sm.Where(LocationsPackagedownloadtaskfiles.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsPackagedownloadtaskfile is retrieved from the database +func (o *LocationsPackagedownloadtaskfile) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPackagedownloadtaskfiles.AfterSelectHooks.RunHooks(ctx, exec, LocationsPackagedownloadtaskfileSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsPackagedownloadtaskfiles.AfterInsertHooks.RunHooks(ctx, exec, LocationsPackagedownloadtaskfileSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsPackagedownloadtaskfiles.AfterUpdateHooks.RunHooks(ctx, exec, LocationsPackagedownloadtaskfileSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsPackagedownloadtaskfiles.AfterDeleteHooks.RunHooks(ctx, exec, LocationsPackagedownloadtaskfileSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsPackagedownloadtaskfile +func (o *LocationsPackagedownloadtaskfile) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsPackagedownloadtaskfile) pkEQ() dialect.Expression { + return mysql.Quote("locations_packagedownloadtaskfile", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsPackagedownloadtaskfile +func (o *LocationsPackagedownloadtaskfile) Update(ctx context.Context, exec bob.Executor, s *LocationsPackagedownloadtaskfileSetter) error { + _, err := LocationsPackagedownloadtaskfiles.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsPackagedownloadtaskfile record with an executor +func (o *LocationsPackagedownloadtaskfile) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsPackagedownloadtaskfiles.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsPackagedownloadtaskfile using the executor +func (o *LocationsPackagedownloadtaskfile) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsPackagedownloadtaskfiles.Query( + sm.Where(LocationsPackagedownloadtaskfiles.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsPackagedownloadtaskfileSlice is retrieved from the database +func (o LocationsPackagedownloadtaskfileSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPackagedownloadtaskfiles.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsPackagedownloadtaskfiles.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsPackagedownloadtaskfiles.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsPackagedownloadtaskfiles.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsPackagedownloadtaskfileSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_packagedownloadtaskfile", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsPackagedownloadtaskfileSlice) copyMatchingRows(from ...*LocationsPackagedownloadtaskfile) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsPackagedownloadtaskfileSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackagedownloadtaskfiles.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPackagedownloadtaskfile: + o.copyMatchingRows(retrieved) + case []*LocationsPackagedownloadtaskfile: + o.copyMatchingRows(retrieved...) + case LocationsPackagedownloadtaskfileSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPackagedownloadtaskfile or a slice of LocationsPackagedownloadtaskfile + // then run the AfterUpdateHooks on the slice + _, err = LocationsPackagedownloadtaskfiles.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsPackagedownloadtaskfileSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPackagedownloadtaskfiles.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPackagedownloadtaskfile: + o.copyMatchingRows(retrieved) + case []*LocationsPackagedownloadtaskfile: + o.copyMatchingRows(retrieved...) + case LocationsPackagedownloadtaskfileSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPackagedownloadtaskfile or a slice of LocationsPackagedownloadtaskfile + // then run the AfterDeleteHooks on the slice + _, err = LocationsPackagedownloadtaskfiles.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsPackagedownloadtaskfileSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsPackagedownloadtaskfileSetter) error { + _, err := LocationsPackagedownloadtaskfiles.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsPackagedownloadtaskfileSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsPackagedownloadtaskfiles.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsPackagedownloadtaskfileSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsPackagedownloadtaskfiles.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// TaskLocationsPackagedownloadtask starts a query for related objects on locations_packagedownloadtask +func (o *LocationsPackagedownloadtaskfile) TaskLocationsPackagedownloadtask(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagedownloadtasksQuery { + return LocationsPackagedownloadtasks.Query(append(mods, + sm.Where(LocationsPackagedownloadtasks.Columns.UUID.EQ(mysql.Arg(o.TaskID))), + )...) +} + +func (os LocationsPackagedownloadtaskfileSlice) TaskLocationsPackagedownloadtask(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagedownloadtasksQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.TaskID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackagedownloadtasks.Query(append(mods, + sm.Where(mysql.Group(LocationsPackagedownloadtasks.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsPackagedownloadtaskfileTaskLocationsPackagedownloadtask0(ctx context.Context, exec bob.Executor, count int, locationsPackagedownloadtaskfile0 *LocationsPackagedownloadtaskfile, locationsPackagedownloadtask1 *LocationsPackagedownloadtask) (*LocationsPackagedownloadtaskfile, error) { + setter := &LocationsPackagedownloadtaskfileSetter{ + TaskID: omit.From(locationsPackagedownloadtask1.UUID), + } + + err := locationsPackagedownloadtaskfile0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPackagedownloadtaskfileTaskLocationsPackagedownloadtask0: %w", err) + } + + return locationsPackagedownloadtaskfile0, nil +} + +func (locationsPackagedownloadtaskfile0 *LocationsPackagedownloadtaskfile) InsertTaskLocationsPackagedownloadtask(ctx context.Context, exec bob.Executor, related *LocationsPackagedownloadtaskSetter) error { + var err error + + locationsPackagedownloadtask1, err := LocationsPackagedownloadtasks.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPackagedownloadtaskfileTaskLocationsPackagedownloadtask0(ctx, exec, 1, locationsPackagedownloadtaskfile0, locationsPackagedownloadtask1) + if err != nil { + return err + } + + locationsPackagedownloadtaskfile0.R.TaskLocationsPackagedownloadtask = locationsPackagedownloadtask1 + + locationsPackagedownloadtask1.R.UUIDLocationsPackagedownloadtaskfiles = append(locationsPackagedownloadtask1.R.UUIDLocationsPackagedownloadtaskfiles, locationsPackagedownloadtaskfile0) + + return nil +} + +func (locationsPackagedownloadtaskfile0 *LocationsPackagedownloadtaskfile) AttachTaskLocationsPackagedownloadtask(ctx context.Context, exec bob.Executor, locationsPackagedownloadtask1 *LocationsPackagedownloadtask) error { + var err error + + _, err = attachLocationsPackagedownloadtaskfileTaskLocationsPackagedownloadtask0(ctx, exec, 1, locationsPackagedownloadtaskfile0, locationsPackagedownloadtask1) + if err != nil { + return err + } + + locationsPackagedownloadtaskfile0.R.TaskLocationsPackagedownloadtask = locationsPackagedownloadtask1 + + locationsPackagedownloadtask1.R.UUIDLocationsPackagedownloadtaskfiles = append(locationsPackagedownloadtask1.R.UUIDLocationsPackagedownloadtaskfiles, locationsPackagedownloadtaskfile0) + + return nil +} + +type locationsPackagedownloadtaskfileWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UUID mysql.WhereMod[Q, string] + Filename mysql.WhereMod[Q, string] + URL mysql.WhereMod[Q, string] + Completed mysql.WhereMod[Q, bool] + Failed mysql.WhereMod[Q, bool] + TaskID mysql.WhereMod[Q, string] +} + +func (locationsPackagedownloadtaskfileWhere[Q]) AliasedAs(alias string) locationsPackagedownloadtaskfileWhere[Q] { + return buildLocationsPackagedownloadtaskfileWhere[Q](buildLocationsPackagedownloadtaskfileColumns(alias)) +} + +func buildLocationsPackagedownloadtaskfileWhere[Q mysql.Filterable](cols locationsPackagedownloadtaskfileColumns) locationsPackagedownloadtaskfileWhere[Q] { + return locationsPackagedownloadtaskfileWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UUID: mysql.Where[Q, string](cols.UUID), + Filename: mysql.Where[Q, string](cols.Filename), + URL: mysql.Where[Q, string](cols.URL), + Completed: mysql.Where[Q, bool](cols.Completed), + Failed: mysql.Where[Q, bool](cols.Failed), + TaskID: mysql.Where[Q, string](cols.TaskID), + } +} + +func (o *LocationsPackagedownloadtaskfile) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "TaskLocationsPackagedownloadtask": + rel, ok := retrieved.(*LocationsPackagedownloadtask) + if !ok { + return fmt.Errorf("locationsPackagedownloadtaskfile cannot load %T as %q", retrieved, name) + } + + o.R.TaskLocationsPackagedownloadtask = rel + + if rel != nil { + rel.R.UUIDLocationsPackagedownloadtaskfiles = LocationsPackagedownloadtaskfileSlice{o} + } + return nil + default: + return fmt.Errorf("locationsPackagedownloadtaskfile has no relationship %q", name) + } +} + +type locationsPackagedownloadtaskfilePreloader struct { + TaskLocationsPackagedownloadtask func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsPackagedownloadtaskfilePreloader() locationsPackagedownloadtaskfilePreloader { + return locationsPackagedownloadtaskfilePreloader{ + TaskLocationsPackagedownloadtask: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPackagedownloadtask, LocationsPackagedownloadtaskSlice](mysql.PreloadRel{ + Name: "TaskLocationsPackagedownloadtask", + Sides: []mysql.PreloadSide{ + { + From: LocationsPackagedownloadtaskfiles, + To: LocationsPackagedownloadtasks, + FromColumns: []string{"task_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsPackagedownloadtasks.Columns.Names(), opts...) + }, + } +} + +type locationsPackagedownloadtaskfileThenLoader[Q orm.Loadable] struct { + TaskLocationsPackagedownloadtask func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsPackagedownloadtaskfileThenLoader[Q orm.Loadable]() locationsPackagedownloadtaskfileThenLoader[Q] { + type TaskLocationsPackagedownloadtaskLoadInterface interface { + LoadTaskLocationsPackagedownloadtask(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsPackagedownloadtaskfileThenLoader[Q]{ + TaskLocationsPackagedownloadtask: thenLoadBuilder[Q]( + "TaskLocationsPackagedownloadtask", + func(ctx context.Context, exec bob.Executor, retrieved TaskLocationsPackagedownloadtaskLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadTaskLocationsPackagedownloadtask(ctx, exec, mods...) + }, + ), + } +} + +// LoadTaskLocationsPackagedownloadtask loads the locationsPackagedownloadtaskfile's TaskLocationsPackagedownloadtask into the .R struct +func (o *LocationsPackagedownloadtaskfile) LoadTaskLocationsPackagedownloadtask(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.TaskLocationsPackagedownloadtask = nil + + related, err := o.TaskLocationsPackagedownloadtask(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.UUIDLocationsPackagedownloadtaskfiles = LocationsPackagedownloadtaskfileSlice{o} + + o.R.TaskLocationsPackagedownloadtask = related + return nil +} + +// LoadTaskLocationsPackagedownloadtask loads the locationsPackagedownloadtaskfile's TaskLocationsPackagedownloadtask into the .R struct +func (os LocationsPackagedownloadtaskfileSlice) LoadTaskLocationsPackagedownloadtask(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackagedownloadtasks, err := os.TaskLocationsPackagedownloadtask(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackagedownloadtasks { + + if !(o.TaskID == rel.UUID) { + continue + } + + rel.R.UUIDLocationsPackagedownloadtaskfiles = append(rel.R.UUIDLocationsPackagedownloadtaskfiles, o) + + o.R.TaskLocationsPackagedownloadtask = rel + break + } + } + + return nil +} + +type locationsPackagedownloadtaskfileJoins[Q dialect.Joinable] struct { + typ string + TaskLocationsPackagedownloadtask modAs[Q, locationsPackagedownloadtaskColumns] +} + +func (j locationsPackagedownloadtaskfileJoins[Q]) aliasedAs(alias string) locationsPackagedownloadtaskfileJoins[Q] { + return buildLocationsPackagedownloadtaskfileJoins[Q](buildLocationsPackagedownloadtaskfileColumns(alias), j.typ) +} + +func buildLocationsPackagedownloadtaskfileJoins[Q dialect.Joinable](cols locationsPackagedownloadtaskfileColumns, typ string) locationsPackagedownloadtaskfileJoins[Q] { + return locationsPackagedownloadtaskfileJoins[Q]{ + typ: typ, + TaskLocationsPackagedownloadtask: modAs[Q, locationsPackagedownloadtaskColumns]{ + c: LocationsPackagedownloadtasks.Columns, + f: func(to locationsPackagedownloadtaskColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackagedownloadtasks.Name().As(to.Alias())).On( + to.UUID.EQ(cols.TaskID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_pipeline.bob.go b/database/storage_service/models/locations_pipeline.bob.go new file mode 100644 index 0000000..6b8d97a --- /dev/null +++ b/database/storage_service/models/locations_pipeline.bob.go @@ -0,0 +1,1108 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsPipeline is an object representing the database table. +type LocationsPipeline struct { + ID int32 `db:"id,pk,autoincr" ` + UUID string `db:"uuid" ` + Description null.Val[string] `db:"description" ` + Enabled bool `db:"enabled" ` + APIKey null.Val[string] `db:"api_key" ` + APIUsername null.Val[string] `db:"api_username" ` + RemoteName null.Val[string] `db:"remote_name" ` + + R locationsPipelineR `db:"-" ` +} + +// LocationsPipelineSlice is an alias for a slice of pointers to LocationsPipeline. +// This should almost always be used instead of []*LocationsPipeline. +type LocationsPipelineSlice []*LocationsPipeline + +// LocationsPipelines contains methods to work with the locations_pipeline table +var LocationsPipelines = mysql.NewTablex[*LocationsPipeline, LocationsPipelineSlice, *LocationsPipelineSetter]("locations_pipeline", buildLocationsPipelineColumns("locations_pipeline"), []string{"id"}, []string{"uuid"}) + +// LocationsPipelinesQuery is a query on the locations_pipeline table +type LocationsPipelinesQuery = *mysql.ViewQuery[*LocationsPipeline, LocationsPipelineSlice] + +// locationsPipelineR is where relationships are stored. +type locationsPipelineR struct { + PipelineLocationsEvents LocationsEventSlice // locations_event_pipeline_id_5188361f_fk_locations_pipeline_uuid + PipelineLocationsLocationpipelines LocationsLocationpipelineSlice // locations_locationpi_pipeline_id_2ad721b4_fk_locations + OriginPipelineLocationsPackages LocationsPackageSlice // locations_package_origin_pipeline_id_9f8d6473_fk_locations +} + +func buildLocationsPipelineColumns(alias string) locationsPipelineColumns { + return locationsPipelineColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "uuid", "description", "enabled", "api_key", "api_username", "remote_name", + ).WithParent("locations_pipeline"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UUID: mysql.Quote(alias, "uuid"), + Description: mysql.Quote(alias, "description"), + Enabled: mysql.Quote(alias, "enabled"), + APIKey: mysql.Quote(alias, "api_key"), + APIUsername: mysql.Quote(alias, "api_username"), + RemoteName: mysql.Quote(alias, "remote_name"), + } +} + +type locationsPipelineColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UUID mysql.Expression + Description mysql.Expression + Enabled mysql.Expression + APIKey mysql.Expression + APIUsername mysql.Expression + RemoteName mysql.Expression +} + +func (c locationsPipelineColumns) Alias() string { + return c.tableAlias +} + +func (locationsPipelineColumns) AliasedAs(alias string) locationsPipelineColumns { + return buildLocationsPipelineColumns(alias) +} + +// LocationsPipelineSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsPipelineSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UUID omit.Val[string] `db:"uuid" ` + Description omitnull.Val[string] `db:"description" ` + Enabled omit.Val[bool] `db:"enabled" ` + APIKey omitnull.Val[string] `db:"api_key" ` + APIUsername omitnull.Val[string] `db:"api_username" ` + RemoteName omitnull.Val[string] `db:"remote_name" ` +} + +func (s LocationsPipelineSetter) SetColumns() []string { + vals := make([]string, 0, 7) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UUID.IsValue() { + vals = append(vals, "uuid") + } + if !s.Description.IsUnset() { + vals = append(vals, "description") + } + if s.Enabled.IsValue() { + vals = append(vals, "enabled") + } + if !s.APIKey.IsUnset() { + vals = append(vals, "api_key") + } + if !s.APIUsername.IsUnset() { + vals = append(vals, "api_username") + } + if !s.RemoteName.IsUnset() { + vals = append(vals, "remote_name") + } + return vals +} + +func (s LocationsPipelineSetter) Overwrite(t *LocationsPipeline) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UUID.IsValue() { + t.UUID = s.UUID.MustGet() + } + if !s.Description.IsUnset() { + t.Description = s.Description.MustGetNull() + } + if s.Enabled.IsValue() { + t.Enabled = s.Enabled.MustGet() + } + if !s.APIKey.IsUnset() { + t.APIKey = s.APIKey.MustGetNull() + } + if !s.APIUsername.IsUnset() { + t.APIUsername = s.APIUsername.MustGetNull() + } + if !s.RemoteName.IsUnset() { + t.RemoteName = s.RemoteName.MustGetNull() + } +} + +func (s *LocationsPipelineSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPipelines.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UUID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UUID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Description.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Description.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Enabled.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Enabled.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.APIKey.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.APIKey.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.APIUsername.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.APIUsername.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.RemoteName.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RemoteName.MustGetNull()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsPipelineSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_pipeline")...) +} + +func (s LocationsPipelineSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 7) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UUID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uuid")...), + mysql.Arg(s.UUID), + }}) + } + + if !s.Description.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "description")...), + mysql.Arg(s.Description), + }}) + } + + if s.Enabled.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "enabled")...), + mysql.Arg(s.Enabled), + }}) + } + + if !s.APIKey.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "api_key")...), + mysql.Arg(s.APIKey), + }}) + } + + if !s.APIUsername.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "api_username")...), + mysql.Arg(s.APIUsername), + }}) + } + + if !s.RemoteName.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "remote_name")...), + mysql.Arg(s.RemoteName), + }}) + } + + return exprs +} + +// FindLocationsPipeline retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsPipeline(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsPipeline, error) { + if len(cols) == 0 { + return LocationsPipelines.Query( + sm.Where(LocationsPipelines.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsPipelines.Query( + sm.Where(LocationsPipelines.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsPipelines.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsPipelineExists checks the presence of a single record by primary key +func LocationsPipelineExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsPipelines.Query( + sm.Where(LocationsPipelines.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsPipeline is retrieved from the database +func (o *LocationsPipeline) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPipelines.AfterSelectHooks.RunHooks(ctx, exec, LocationsPipelineSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsPipelines.AfterInsertHooks.RunHooks(ctx, exec, LocationsPipelineSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsPipelines.AfterUpdateHooks.RunHooks(ctx, exec, LocationsPipelineSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsPipelines.AfterDeleteHooks.RunHooks(ctx, exec, LocationsPipelineSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsPipeline +func (o *LocationsPipeline) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsPipeline) pkEQ() dialect.Expression { + return mysql.Quote("locations_pipeline", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsPipeline +func (o *LocationsPipeline) Update(ctx context.Context, exec bob.Executor, s *LocationsPipelineSetter) error { + _, err := LocationsPipelines.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsPipeline record with an executor +func (o *LocationsPipeline) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsPipelines.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsPipeline using the executor +func (o *LocationsPipeline) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsPipelines.Query( + sm.Where(LocationsPipelines.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsPipelineSlice is retrieved from the database +func (o LocationsPipelineSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPipelines.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsPipelines.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsPipelines.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsPipelines.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsPipelineSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_pipeline", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsPipelineSlice) copyMatchingRows(from ...*LocationsPipeline) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsPipelineSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPipelines.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPipeline: + o.copyMatchingRows(retrieved) + case []*LocationsPipeline: + o.copyMatchingRows(retrieved...) + case LocationsPipelineSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPipeline or a slice of LocationsPipeline + // then run the AfterUpdateHooks on the slice + _, err = LocationsPipelines.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsPipelineSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPipelines.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPipeline: + o.copyMatchingRows(retrieved) + case []*LocationsPipeline: + o.copyMatchingRows(retrieved...) + case LocationsPipelineSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPipeline or a slice of LocationsPipeline + // then run the AfterDeleteHooks on the slice + _, err = LocationsPipelines.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsPipelineSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsPipelineSetter) error { + _, err := LocationsPipelines.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsPipelineSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsPipelines.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsPipelineSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsPipelines.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// PipelineLocationsEvents starts a query for related objects on locations_event +func (o *LocationsPipeline) PipelineLocationsEvents(mods ...bob.Mod[*dialect.SelectQuery]) LocationsEventsQuery { + return LocationsEvents.Query(append(mods, + sm.Where(LocationsEvents.Columns.PipelineID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsPipelineSlice) PipelineLocationsEvents(mods ...bob.Mod[*dialect.SelectQuery]) LocationsEventsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsEvents.Query(append(mods, + sm.Where(mysql.Group(LocationsEvents.Columns.PipelineID).OP("IN", PKArgExpr)), + )...) +} + +// PipelineLocationsLocationpipelines starts a query for related objects on locations_locationpipeline +func (o *LocationsPipeline) PipelineLocationsLocationpipelines(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationpipelinesQuery { + return LocationsLocationpipelines.Query(append(mods, + sm.Where(LocationsLocationpipelines.Columns.PipelineID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsPipelineSlice) PipelineLocationsLocationpipelines(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationpipelinesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocationpipelines.Query(append(mods, + sm.Where(mysql.Group(LocationsLocationpipelines.Columns.PipelineID).OP("IN", PKArgExpr)), + )...) +} + +// OriginPipelineLocationsPackages starts a query for related objects on locations_package +func (o *LocationsPipeline) OriginPipelineLocationsPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + return LocationsPackages.Query(append(mods, + sm.Where(LocationsPackages.Columns.OriginPipelineID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsPipelineSlice) OriginPipelineLocationsPackages(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPackagesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPackages.Query(append(mods, + sm.Where(mysql.Group(LocationsPackages.Columns.OriginPipelineID).OP("IN", PKArgExpr)), + )...) +} + +func insertLocationsPipelinePipelineLocationsEvents0(ctx context.Context, exec bob.Executor, locationsEvents1 []*LocationsEventSetter, locationsPipeline0 *LocationsPipeline) (LocationsEventSlice, error) { + for i := range locationsEvents1 { + locationsEvents1[i].PipelineID = omit.From(locationsPipeline0.UUID) + } + + ret, err := LocationsEvents.Insert(bob.ToMods(locationsEvents1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPipelinePipelineLocationsEvents0: %w", err) + } + + return ret, nil +} + +func attachLocationsPipelinePipelineLocationsEvents0(ctx context.Context, exec bob.Executor, count int, locationsEvents1 LocationsEventSlice, locationsPipeline0 *LocationsPipeline) (LocationsEventSlice, error) { + setter := &LocationsEventSetter{ + PipelineID: omit.From(locationsPipeline0.UUID), + } + + err := locationsEvents1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPipelinePipelineLocationsEvents0: %w", err) + } + + return locationsEvents1, nil +} + +func (locationsPipeline0 *LocationsPipeline) InsertPipelineLocationsEvents(ctx context.Context, exec bob.Executor, related ...*LocationsEventSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsEvents1, err := insertLocationsPipelinePipelineLocationsEvents0(ctx, exec, related, locationsPipeline0) + if err != nil { + return err + } + + locationsPipeline0.R.PipelineLocationsEvents = append(locationsPipeline0.R.PipelineLocationsEvents, locationsEvents1...) + + for _, rel := range locationsEvents1 { + rel.R.PipelineLocationsPipeline = locationsPipeline0 + } + return nil +} + +func (locationsPipeline0 *LocationsPipeline) AttachPipelineLocationsEvents(ctx context.Context, exec bob.Executor, related ...*LocationsEvent) error { + if len(related) == 0 { + return nil + } + + var err error + locationsEvents1 := LocationsEventSlice(related) + + _, err = attachLocationsPipelinePipelineLocationsEvents0(ctx, exec, len(related), locationsEvents1, locationsPipeline0) + if err != nil { + return err + } + + locationsPipeline0.R.PipelineLocationsEvents = append(locationsPipeline0.R.PipelineLocationsEvents, locationsEvents1...) + + for _, rel := range related { + rel.R.PipelineLocationsPipeline = locationsPipeline0 + } + + return nil +} + +func insertLocationsPipelinePipelineLocationsLocationpipelines0(ctx context.Context, exec bob.Executor, locationsLocationpipelines1 []*LocationsLocationpipelineSetter, locationsPipeline0 *LocationsPipeline) (LocationsLocationpipelineSlice, error) { + for i := range locationsLocationpipelines1 { + locationsLocationpipelines1[i].PipelineID = omit.From(locationsPipeline0.UUID) + } + + ret, err := LocationsLocationpipelines.Insert(bob.ToMods(locationsLocationpipelines1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPipelinePipelineLocationsLocationpipelines0: %w", err) + } + + return ret, nil +} + +func attachLocationsPipelinePipelineLocationsLocationpipelines0(ctx context.Context, exec bob.Executor, count int, locationsLocationpipelines1 LocationsLocationpipelineSlice, locationsPipeline0 *LocationsPipeline) (LocationsLocationpipelineSlice, error) { + setter := &LocationsLocationpipelineSetter{ + PipelineID: omit.From(locationsPipeline0.UUID), + } + + err := locationsLocationpipelines1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPipelinePipelineLocationsLocationpipelines0: %w", err) + } + + return locationsLocationpipelines1, nil +} + +func (locationsPipeline0 *LocationsPipeline) InsertPipelineLocationsLocationpipelines(ctx context.Context, exec bob.Executor, related ...*LocationsLocationpipelineSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsLocationpipelines1, err := insertLocationsPipelinePipelineLocationsLocationpipelines0(ctx, exec, related, locationsPipeline0) + if err != nil { + return err + } + + locationsPipeline0.R.PipelineLocationsLocationpipelines = append(locationsPipeline0.R.PipelineLocationsLocationpipelines, locationsLocationpipelines1...) + + for _, rel := range locationsLocationpipelines1 { + rel.R.PipelineLocationsPipeline = locationsPipeline0 + } + return nil +} + +func (locationsPipeline0 *LocationsPipeline) AttachPipelineLocationsLocationpipelines(ctx context.Context, exec bob.Executor, related ...*LocationsLocationpipeline) error { + if len(related) == 0 { + return nil + } + + var err error + locationsLocationpipelines1 := LocationsLocationpipelineSlice(related) + + _, err = attachLocationsPipelinePipelineLocationsLocationpipelines0(ctx, exec, len(related), locationsLocationpipelines1, locationsPipeline0) + if err != nil { + return err + } + + locationsPipeline0.R.PipelineLocationsLocationpipelines = append(locationsPipeline0.R.PipelineLocationsLocationpipelines, locationsLocationpipelines1...) + + for _, rel := range related { + rel.R.PipelineLocationsPipeline = locationsPipeline0 + } + + return nil +} + +func insertLocationsPipelineOriginPipelineLocationsPackages0(ctx context.Context, exec bob.Executor, locationsPackages1 []*LocationsPackageSetter, locationsPipeline0 *LocationsPipeline) (LocationsPackageSlice, error) { + for i := range locationsPackages1 { + locationsPackages1[i].OriginPipelineID = omitnull.From(locationsPipeline0.UUID) + } + + ret, err := LocationsPackages.Insert(bob.ToMods(locationsPackages1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsPipelineOriginPipelineLocationsPackages0: %w", err) + } + + return ret, nil +} + +func attachLocationsPipelineOriginPipelineLocationsPackages0(ctx context.Context, exec bob.Executor, count int, locationsPackages1 LocationsPackageSlice, locationsPipeline0 *LocationsPipeline) (LocationsPackageSlice, error) { + setter := &LocationsPackageSetter{ + OriginPipelineID: omitnull.From(locationsPipeline0.UUID), + } + + err := locationsPackages1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPipelineOriginPipelineLocationsPackages0: %w", err) + } + + return locationsPackages1, nil +} + +func (locationsPipeline0 *LocationsPipeline) InsertOriginPipelineLocationsPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackageSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsPackages1, err := insertLocationsPipelineOriginPipelineLocationsPackages0(ctx, exec, related, locationsPipeline0) + if err != nil { + return err + } + + locationsPipeline0.R.OriginPipelineLocationsPackages = append(locationsPipeline0.R.OriginPipelineLocationsPackages, locationsPackages1...) + + for _, rel := range locationsPackages1 { + rel.R.OriginPipelineLocationsPipeline = locationsPipeline0 + } + return nil +} + +func (locationsPipeline0 *LocationsPipeline) AttachOriginPipelineLocationsPackages(ctx context.Context, exec bob.Executor, related ...*LocationsPackage) error { + if len(related) == 0 { + return nil + } + + var err error + locationsPackages1 := LocationsPackageSlice(related) + + _, err = attachLocationsPipelineOriginPipelineLocationsPackages0(ctx, exec, len(related), locationsPackages1, locationsPipeline0) + if err != nil { + return err + } + + locationsPipeline0.R.OriginPipelineLocationsPackages = append(locationsPipeline0.R.OriginPipelineLocationsPackages, locationsPackages1...) + + for _, rel := range related { + rel.R.OriginPipelineLocationsPipeline = locationsPipeline0 + } + + return nil +} + +type locationsPipelineWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UUID mysql.WhereMod[Q, string] + Description mysql.WhereNullMod[Q, string] + Enabled mysql.WhereMod[Q, bool] + APIKey mysql.WhereNullMod[Q, string] + APIUsername mysql.WhereNullMod[Q, string] + RemoteName mysql.WhereNullMod[Q, string] +} + +func (locationsPipelineWhere[Q]) AliasedAs(alias string) locationsPipelineWhere[Q] { + return buildLocationsPipelineWhere[Q](buildLocationsPipelineColumns(alias)) +} + +func buildLocationsPipelineWhere[Q mysql.Filterable](cols locationsPipelineColumns) locationsPipelineWhere[Q] { + return locationsPipelineWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UUID: mysql.Where[Q, string](cols.UUID), + Description: mysql.WhereNull[Q, string](cols.Description), + Enabled: mysql.Where[Q, bool](cols.Enabled), + APIKey: mysql.WhereNull[Q, string](cols.APIKey), + APIUsername: mysql.WhereNull[Q, string](cols.APIUsername), + RemoteName: mysql.WhereNull[Q, string](cols.RemoteName), + } +} + +func (o *LocationsPipeline) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "PipelineLocationsEvents": + rels, ok := retrieved.(LocationsEventSlice) + if !ok { + return fmt.Errorf("locationsPipeline cannot load %T as %q", retrieved, name) + } + + o.R.PipelineLocationsEvents = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PipelineLocationsPipeline = o + } + } + return nil + case "PipelineLocationsLocationpipelines": + rels, ok := retrieved.(LocationsLocationpipelineSlice) + if !ok { + return fmt.Errorf("locationsPipeline cannot load %T as %q", retrieved, name) + } + + o.R.PipelineLocationsLocationpipelines = rels + + for _, rel := range rels { + if rel != nil { + rel.R.PipelineLocationsPipeline = o + } + } + return nil + case "OriginPipelineLocationsPackages": + rels, ok := retrieved.(LocationsPackageSlice) + if !ok { + return fmt.Errorf("locationsPipeline cannot load %T as %q", retrieved, name) + } + + o.R.OriginPipelineLocationsPackages = rels + + for _, rel := range rels { + if rel != nil { + rel.R.OriginPipelineLocationsPipeline = o + } + } + return nil + default: + return fmt.Errorf("locationsPipeline has no relationship %q", name) + } +} + +type locationsPipelinePreloader struct{} + +func buildLocationsPipelinePreloader() locationsPipelinePreloader { + return locationsPipelinePreloader{} +} + +type locationsPipelineThenLoader[Q orm.Loadable] struct { + PipelineLocationsEvents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + PipelineLocationsLocationpipelines func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + OriginPipelineLocationsPackages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsPipelineThenLoader[Q orm.Loadable]() locationsPipelineThenLoader[Q] { + type PipelineLocationsEventsLoadInterface interface { + LoadPipelineLocationsEvents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type PipelineLocationsLocationpipelinesLoadInterface interface { + LoadPipelineLocationsLocationpipelines(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type OriginPipelineLocationsPackagesLoadInterface interface { + LoadOriginPipelineLocationsPackages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsPipelineThenLoader[Q]{ + PipelineLocationsEvents: thenLoadBuilder[Q]( + "PipelineLocationsEvents", + func(ctx context.Context, exec bob.Executor, retrieved PipelineLocationsEventsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPipelineLocationsEvents(ctx, exec, mods...) + }, + ), + PipelineLocationsLocationpipelines: thenLoadBuilder[Q]( + "PipelineLocationsLocationpipelines", + func(ctx context.Context, exec bob.Executor, retrieved PipelineLocationsLocationpipelinesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPipelineLocationsLocationpipelines(ctx, exec, mods...) + }, + ), + OriginPipelineLocationsPackages: thenLoadBuilder[Q]( + "OriginPipelineLocationsPackages", + func(ctx context.Context, exec bob.Executor, retrieved OriginPipelineLocationsPackagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadOriginPipelineLocationsPackages(ctx, exec, mods...) + }, + ), + } +} + +// LoadPipelineLocationsEvents loads the locationsPipeline's PipelineLocationsEvents into the .R struct +func (o *LocationsPipeline) LoadPipelineLocationsEvents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PipelineLocationsEvents = nil + + related, err := o.PipelineLocationsEvents(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PipelineLocationsPipeline = o + } + + o.R.PipelineLocationsEvents = related + return nil +} + +// LoadPipelineLocationsEvents loads the locationsPipeline's PipelineLocationsEvents into the .R struct +func (os LocationsPipelineSlice) LoadPipelineLocationsEvents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsEvents, err := os.PipelineLocationsEvents(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PipelineLocationsEvents = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsEvents { + + if !(o.UUID == rel.PipelineID) { + continue + } + + rel.R.PipelineLocationsPipeline = o + + o.R.PipelineLocationsEvents = append(o.R.PipelineLocationsEvents, rel) + } + } + + return nil +} + +// LoadPipelineLocationsLocationpipelines loads the locationsPipeline's PipelineLocationsLocationpipelines into the .R struct +func (o *LocationsPipeline) LoadPipelineLocationsLocationpipelines(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.PipelineLocationsLocationpipelines = nil + + related, err := o.PipelineLocationsLocationpipelines(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.PipelineLocationsPipeline = o + } + + o.R.PipelineLocationsLocationpipelines = related + return nil +} + +// LoadPipelineLocationsLocationpipelines loads the locationsPipeline's PipelineLocationsLocationpipelines into the .R struct +func (os LocationsPipelineSlice) LoadPipelineLocationsLocationpipelines(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocationpipelines, err := os.PipelineLocationsLocationpipelines(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.PipelineLocationsLocationpipelines = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocationpipelines { + + if !(o.UUID == rel.PipelineID) { + continue + } + + rel.R.PipelineLocationsPipeline = o + + o.R.PipelineLocationsLocationpipelines = append(o.R.PipelineLocationsLocationpipelines, rel) + } + } + + return nil +} + +// LoadOriginPipelineLocationsPackages loads the locationsPipeline's OriginPipelineLocationsPackages into the .R struct +func (o *LocationsPipeline) LoadOriginPipelineLocationsPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.OriginPipelineLocationsPackages = nil + + related, err := o.OriginPipelineLocationsPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.OriginPipelineLocationsPipeline = o + } + + o.R.OriginPipelineLocationsPackages = related + return nil +} + +// LoadOriginPipelineLocationsPackages loads the locationsPipeline's OriginPipelineLocationsPackages into the .R struct +func (os LocationsPipelineSlice) LoadOriginPipelineLocationsPackages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPackages, err := os.OriginPipelineLocationsPackages(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.OriginPipelineLocationsPackages = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPackages { + + if !rel.OriginPipelineID.IsValue() { + continue + } + if !(rel.OriginPipelineID.IsValue() && o.UUID == rel.OriginPipelineID.MustGet()) { + continue + } + + rel.R.OriginPipelineLocationsPipeline = o + + o.R.OriginPipelineLocationsPackages = append(o.R.OriginPipelineLocationsPackages, rel) + } + } + + return nil +} + +type locationsPipelineJoins[Q dialect.Joinable] struct { + typ string + PipelineLocationsEvents modAs[Q, locationsEventColumns] + PipelineLocationsLocationpipelines modAs[Q, locationsLocationpipelineColumns] + OriginPipelineLocationsPackages modAs[Q, locationsPackageColumns] +} + +func (j locationsPipelineJoins[Q]) aliasedAs(alias string) locationsPipelineJoins[Q] { + return buildLocationsPipelineJoins[Q](buildLocationsPipelineColumns(alias), j.typ) +} + +func buildLocationsPipelineJoins[Q dialect.Joinable](cols locationsPipelineColumns, typ string) locationsPipelineJoins[Q] { + return locationsPipelineJoins[Q]{ + typ: typ, + PipelineLocationsEvents: modAs[Q, locationsEventColumns]{ + c: LocationsEvents.Columns, + f: func(to locationsEventColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsEvents.Name().As(to.Alias())).On( + to.PipelineID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + PipelineLocationsLocationpipelines: modAs[Q, locationsLocationpipelineColumns]{ + c: LocationsLocationpipelines.Columns, + f: func(to locationsLocationpipelineColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocationpipelines.Name().As(to.Alias())).On( + to.PipelineID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + OriginPipelineLocationsPackages: modAs[Q, locationsPackageColumns]{ + c: LocationsPackages.Columns, + f: func(to locationsPackageColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPackages.Name().As(to.Alias())).On( + to.OriginPipelineID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_pipelinelocalfs.bob.go b/database/storage_service/models/locations_pipelinelocalfs.bob.go new file mode 100644 index 0000000..87de74f --- /dev/null +++ b/database/storage_service/models/locations_pipelinelocalfs.bob.go @@ -0,0 +1,688 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsPipelinelocalf is an object representing the database table. +type LocationsPipelinelocalf struct { + ID int32 `db:"id,pk,autoincr" ` + RemoteUser string `db:"remote_user" ` + RemoteName string `db:"remote_name" ` + SpaceID string `db:"space_id" ` + AssumeRsyncDaemon bool `db:"assume_rsync_daemon" ` + RsyncPassword string `db:"rsync_password" ` + + R locationsPipelinelocalfR `db:"-" ` +} + +// LocationsPipelinelocalfSlice is an alias for a slice of pointers to LocationsPipelinelocalf. +// This should almost always be used instead of []*LocationsPipelinelocalf. +type LocationsPipelinelocalfSlice []*LocationsPipelinelocalf + +// LocationsPipelinelocalfs contains methods to work with the locations_pipelinelocalfs table +var LocationsPipelinelocalfs = mysql.NewTablex[*LocationsPipelinelocalf, LocationsPipelinelocalfSlice, *LocationsPipelinelocalfSetter]("locations_pipelinelocalfs", buildLocationsPipelinelocalfColumns("locations_pipelinelocalfs"), []string{"id"}, []string{"space_id"}) + +// LocationsPipelinelocalfsQuery is a query on the locations_pipelinelocalfs table +type LocationsPipelinelocalfsQuery = *mysql.ViewQuery[*LocationsPipelinelocalf, LocationsPipelinelocalfSlice] + +// locationsPipelinelocalfR is where relationships are stored. +type locationsPipelinelocalfR struct { + SpaceLocationsSpace *LocationsSpace // locations_pipelinelo_space_id_6f6ba9f6_fk_locations +} + +func buildLocationsPipelinelocalfColumns(alias string) locationsPipelinelocalfColumns { + return locationsPipelinelocalfColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "remote_user", "remote_name", "space_id", "assume_rsync_daemon", "rsync_password", + ).WithParent("locations_pipelinelocalfs"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + RemoteUser: mysql.Quote(alias, "remote_user"), + RemoteName: mysql.Quote(alias, "remote_name"), + SpaceID: mysql.Quote(alias, "space_id"), + AssumeRsyncDaemon: mysql.Quote(alias, "assume_rsync_daemon"), + RsyncPassword: mysql.Quote(alias, "rsync_password"), + } +} + +type locationsPipelinelocalfColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + RemoteUser mysql.Expression + RemoteName mysql.Expression + SpaceID mysql.Expression + AssumeRsyncDaemon mysql.Expression + RsyncPassword mysql.Expression +} + +func (c locationsPipelinelocalfColumns) Alias() string { + return c.tableAlias +} + +func (locationsPipelinelocalfColumns) AliasedAs(alias string) locationsPipelinelocalfColumns { + return buildLocationsPipelinelocalfColumns(alias) +} + +// LocationsPipelinelocalfSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsPipelinelocalfSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + RemoteUser omit.Val[string] `db:"remote_user" ` + RemoteName omit.Val[string] `db:"remote_name" ` + SpaceID omit.Val[string] `db:"space_id" ` + AssumeRsyncDaemon omit.Val[bool] `db:"assume_rsync_daemon" ` + RsyncPassword omit.Val[string] `db:"rsync_password" ` +} + +func (s LocationsPipelinelocalfSetter) SetColumns() []string { + vals := make([]string, 0, 6) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.RemoteUser.IsValue() { + vals = append(vals, "remote_user") + } + if s.RemoteName.IsValue() { + vals = append(vals, "remote_name") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + if s.AssumeRsyncDaemon.IsValue() { + vals = append(vals, "assume_rsync_daemon") + } + if s.RsyncPassword.IsValue() { + vals = append(vals, "rsync_password") + } + return vals +} + +func (s LocationsPipelinelocalfSetter) Overwrite(t *LocationsPipelinelocalf) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.RemoteUser.IsValue() { + t.RemoteUser = s.RemoteUser.MustGet() + } + if s.RemoteName.IsValue() { + t.RemoteName = s.RemoteName.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } + if s.AssumeRsyncDaemon.IsValue() { + t.AssumeRsyncDaemon = s.AssumeRsyncDaemon.MustGet() + } + if s.RsyncPassword.IsValue() { + t.RsyncPassword = s.RsyncPassword.MustGet() + } +} + +func (s *LocationsPipelinelocalfSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPipelinelocalfs.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.RemoteUser.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RemoteUser.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.RemoteName.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RemoteName.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AssumeRsyncDaemon.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AssumeRsyncDaemon.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.RsyncPassword.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RsyncPassword.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsPipelinelocalfSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_pipelinelocalfs")...) +} + +func (s LocationsPipelinelocalfSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 6) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.RemoteUser.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "remote_user")...), + mysql.Arg(s.RemoteUser), + }}) + } + + if s.RemoteName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "remote_name")...), + mysql.Arg(s.RemoteName), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + if s.AssumeRsyncDaemon.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "assume_rsync_daemon")...), + mysql.Arg(s.AssumeRsyncDaemon), + }}) + } + + if s.RsyncPassword.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "rsync_password")...), + mysql.Arg(s.RsyncPassword), + }}) + } + + return exprs +} + +// FindLocationsPipelinelocalf retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsPipelinelocalf(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsPipelinelocalf, error) { + if len(cols) == 0 { + return LocationsPipelinelocalfs.Query( + sm.Where(LocationsPipelinelocalfs.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsPipelinelocalfs.Query( + sm.Where(LocationsPipelinelocalfs.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsPipelinelocalfs.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsPipelinelocalfExists checks the presence of a single record by primary key +func LocationsPipelinelocalfExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsPipelinelocalfs.Query( + sm.Where(LocationsPipelinelocalfs.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsPipelinelocalf is retrieved from the database +func (o *LocationsPipelinelocalf) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPipelinelocalfs.AfterSelectHooks.RunHooks(ctx, exec, LocationsPipelinelocalfSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsPipelinelocalfs.AfterInsertHooks.RunHooks(ctx, exec, LocationsPipelinelocalfSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsPipelinelocalfs.AfterUpdateHooks.RunHooks(ctx, exec, LocationsPipelinelocalfSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsPipelinelocalfs.AfterDeleteHooks.RunHooks(ctx, exec, LocationsPipelinelocalfSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsPipelinelocalf +func (o *LocationsPipelinelocalf) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsPipelinelocalf) pkEQ() dialect.Expression { + return mysql.Quote("locations_pipelinelocalfs", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsPipelinelocalf +func (o *LocationsPipelinelocalf) Update(ctx context.Context, exec bob.Executor, s *LocationsPipelinelocalfSetter) error { + _, err := LocationsPipelinelocalfs.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsPipelinelocalf record with an executor +func (o *LocationsPipelinelocalf) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsPipelinelocalfs.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsPipelinelocalf using the executor +func (o *LocationsPipelinelocalf) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsPipelinelocalfs.Query( + sm.Where(LocationsPipelinelocalfs.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsPipelinelocalfSlice is retrieved from the database +func (o LocationsPipelinelocalfSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsPipelinelocalfs.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsPipelinelocalfs.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsPipelinelocalfs.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsPipelinelocalfs.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsPipelinelocalfSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_pipelinelocalfs", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsPipelinelocalfSlice) copyMatchingRows(from ...*LocationsPipelinelocalf) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsPipelinelocalfSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPipelinelocalfs.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPipelinelocalf: + o.copyMatchingRows(retrieved) + case []*LocationsPipelinelocalf: + o.copyMatchingRows(retrieved...) + case LocationsPipelinelocalfSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPipelinelocalf or a slice of LocationsPipelinelocalf + // then run the AfterUpdateHooks on the slice + _, err = LocationsPipelinelocalfs.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsPipelinelocalfSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsPipelinelocalfs.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsPipelinelocalf: + o.copyMatchingRows(retrieved) + case []*LocationsPipelinelocalf: + o.copyMatchingRows(retrieved...) + case LocationsPipelinelocalfSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsPipelinelocalf or a slice of LocationsPipelinelocalf + // then run the AfterDeleteHooks on the slice + _, err = LocationsPipelinelocalfs.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsPipelinelocalfSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsPipelinelocalfSetter) error { + _, err := LocationsPipelinelocalfs.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsPipelinelocalfSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsPipelinelocalfs.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsPipelinelocalfSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsPipelinelocalfs.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsPipelinelocalf) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsPipelinelocalfSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsPipelinelocalfSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsPipelinelocalf0 *LocationsPipelinelocalf, locationsSpace1 *LocationsSpace) (*LocationsPipelinelocalf, error) { + setter := &LocationsPipelinelocalfSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsPipelinelocalf0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsPipelinelocalfSpaceLocationsSpace0: %w", err) + } + + return locationsPipelinelocalf0, nil +} + +func (locationsPipelinelocalf0 *LocationsPipelinelocalf) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsPipelinelocalfSpaceLocationsSpace0(ctx, exec, 1, locationsPipelinelocalf0, locationsSpace1) + if err != nil { + return err + } + + locationsPipelinelocalf0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsPipelinelocalf = locationsPipelinelocalf0 + + return nil +} + +func (locationsPipelinelocalf0 *LocationsPipelinelocalf) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsPipelinelocalfSpaceLocationsSpace0(ctx, exec, 1, locationsPipelinelocalf0, locationsSpace1) + if err != nil { + return err + } + + locationsPipelinelocalf0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsPipelinelocalf = locationsPipelinelocalf0 + + return nil +} + +type locationsPipelinelocalfWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + RemoteUser mysql.WhereMod[Q, string] + RemoteName mysql.WhereMod[Q, string] + SpaceID mysql.WhereMod[Q, string] + AssumeRsyncDaemon mysql.WhereMod[Q, bool] + RsyncPassword mysql.WhereMod[Q, string] +} + +func (locationsPipelinelocalfWhere[Q]) AliasedAs(alias string) locationsPipelinelocalfWhere[Q] { + return buildLocationsPipelinelocalfWhere[Q](buildLocationsPipelinelocalfColumns(alias)) +} + +func buildLocationsPipelinelocalfWhere[Q mysql.Filterable](cols locationsPipelinelocalfColumns) locationsPipelinelocalfWhere[Q] { + return locationsPipelinelocalfWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + RemoteUser: mysql.Where[Q, string](cols.RemoteUser), + RemoteName: mysql.Where[Q, string](cols.RemoteName), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + AssumeRsyncDaemon: mysql.Where[Q, bool](cols.AssumeRsyncDaemon), + RsyncPassword: mysql.Where[Q, string](cols.RsyncPassword), + } +} + +func (o *LocationsPipelinelocalf) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsPipelinelocalf cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsPipelinelocalf = o + } + return nil + default: + return fmt.Errorf("locationsPipelinelocalf has no relationship %q", name) + } +} + +type locationsPipelinelocalfPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsPipelinelocalfPreloader() locationsPipelinelocalfPreloader { + return locationsPipelinelocalfPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsPipelinelocalfs, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsPipelinelocalfThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsPipelinelocalfThenLoader[Q orm.Loadable]() locationsPipelinelocalfThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsPipelinelocalfThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsPipelinelocalf's SpaceLocationsSpace into the .R struct +func (o *LocationsPipelinelocalf) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsPipelinelocalf = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsPipelinelocalf's SpaceLocationsSpace into the .R struct +func (os LocationsPipelinelocalfSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsPipelinelocalf = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsPipelinelocalfJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsPipelinelocalfJoins[Q]) aliasedAs(alias string) locationsPipelinelocalfJoins[Q] { + return buildLocationsPipelinelocalfJoins[Q](buildLocationsPipelinelocalfColumns(alias), j.typ) +} + +func buildLocationsPipelinelocalfJoins[Q dialect.Joinable](cols locationsPipelinelocalfColumns, typ string) locationsPipelinelocalfJoins[Q] { + return locationsPipelinelocalfJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_rclone.bob.go b/database/storage_service/models/locations_rclone.bob.go new file mode 100644 index 0000000..0cb3137 --- /dev/null +++ b/database/storage_service/models/locations_rclone.bob.go @@ -0,0 +1,640 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsRclone is an object representing the database table. +type LocationsRclone struct { + ID int32 `db:"id,pk,autoincr" ` + RemoteName string `db:"remote_name" ` + Container string `db:"container" ` + SpaceID string `db:"space_id" ` + + R locationsRcloneR `db:"-" ` +} + +// LocationsRcloneSlice is an alias for a slice of pointers to LocationsRclone. +// This should almost always be used instead of []*LocationsRclone. +type LocationsRcloneSlice []*LocationsRclone + +// LocationsRclones contains methods to work with the locations_rclone table +var LocationsRclones = mysql.NewTablex[*LocationsRclone, LocationsRcloneSlice, *LocationsRcloneSetter]("locations_rclone", buildLocationsRcloneColumns("locations_rclone"), []string{"id"}, []string{"space_id"}) + +// LocationsRclonesQuery is a query on the locations_rclone table +type LocationsRclonesQuery = *mysql.ViewQuery[*LocationsRclone, LocationsRcloneSlice] + +// locationsRcloneR is where relationships are stored. +type locationsRcloneR struct { + SpaceLocationsSpace *LocationsSpace // locations_rclone_space_id_adb7fd1d_fk_locations_space_uuid +} + +func buildLocationsRcloneColumns(alias string) locationsRcloneColumns { + return locationsRcloneColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "remote_name", "container", "space_id", + ).WithParent("locations_rclone"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + RemoteName: mysql.Quote(alias, "remote_name"), + Container: mysql.Quote(alias, "container"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsRcloneColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + RemoteName mysql.Expression + Container mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsRcloneColumns) Alias() string { + return c.tableAlias +} + +func (locationsRcloneColumns) AliasedAs(alias string) locationsRcloneColumns { + return buildLocationsRcloneColumns(alias) +} + +// LocationsRcloneSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsRcloneSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + RemoteName omit.Val[string] `db:"remote_name" ` + Container omit.Val[string] `db:"container" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsRcloneSetter) SetColumns() []string { + vals := make([]string, 0, 4) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.RemoteName.IsValue() { + vals = append(vals, "remote_name") + } + if s.Container.IsValue() { + vals = append(vals, "container") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsRcloneSetter) Overwrite(t *LocationsRclone) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.RemoteName.IsValue() { + t.RemoteName = s.RemoteName.MustGet() + } + if s.Container.IsValue() { + t.Container = s.Container.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsRcloneSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsRclones.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.RemoteName.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RemoteName.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Container.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Container.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsRcloneSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_rclone")...) +} + +func (s LocationsRcloneSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 4) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.RemoteName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "remote_name")...), + mysql.Arg(s.RemoteName), + }}) + } + + if s.Container.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "container")...), + mysql.Arg(s.Container), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsRclone retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsRclone(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsRclone, error) { + if len(cols) == 0 { + return LocationsRclones.Query( + sm.Where(LocationsRclones.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsRclones.Query( + sm.Where(LocationsRclones.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsRclones.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsRcloneExists checks the presence of a single record by primary key +func LocationsRcloneExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsRclones.Query( + sm.Where(LocationsRclones.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsRclone is retrieved from the database +func (o *LocationsRclone) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsRclones.AfterSelectHooks.RunHooks(ctx, exec, LocationsRcloneSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsRclones.AfterInsertHooks.RunHooks(ctx, exec, LocationsRcloneSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsRclones.AfterUpdateHooks.RunHooks(ctx, exec, LocationsRcloneSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsRclones.AfterDeleteHooks.RunHooks(ctx, exec, LocationsRcloneSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsRclone +func (o *LocationsRclone) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsRclone) pkEQ() dialect.Expression { + return mysql.Quote("locations_rclone", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsRclone +func (o *LocationsRclone) Update(ctx context.Context, exec bob.Executor, s *LocationsRcloneSetter) error { + _, err := LocationsRclones.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsRclone record with an executor +func (o *LocationsRclone) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsRclones.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsRclone using the executor +func (o *LocationsRclone) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsRclones.Query( + sm.Where(LocationsRclones.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsRcloneSlice is retrieved from the database +func (o LocationsRcloneSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsRclones.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsRclones.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsRclones.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsRclones.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsRcloneSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_rclone", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsRcloneSlice) copyMatchingRows(from ...*LocationsRclone) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsRcloneSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsRclones.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsRclone: + o.copyMatchingRows(retrieved) + case []*LocationsRclone: + o.copyMatchingRows(retrieved...) + case LocationsRcloneSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsRclone or a slice of LocationsRclone + // then run the AfterUpdateHooks on the slice + _, err = LocationsRclones.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsRcloneSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsRclones.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsRclone: + o.copyMatchingRows(retrieved) + case []*LocationsRclone: + o.copyMatchingRows(retrieved...) + case LocationsRcloneSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsRclone or a slice of LocationsRclone + // then run the AfterDeleteHooks on the slice + _, err = LocationsRclones.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsRcloneSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsRcloneSetter) error { + _, err := LocationsRclones.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsRcloneSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsRclones.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsRcloneSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsRclones.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsRclone) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsRcloneSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsRcloneSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsRclone0 *LocationsRclone, locationsSpace1 *LocationsSpace) (*LocationsRclone, error) { + setter := &LocationsRcloneSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsRclone0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsRcloneSpaceLocationsSpace0: %w", err) + } + + return locationsRclone0, nil +} + +func (locationsRclone0 *LocationsRclone) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsRcloneSpaceLocationsSpace0(ctx, exec, 1, locationsRclone0, locationsSpace1) + if err != nil { + return err + } + + locationsRclone0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsRclone = locationsRclone0 + + return nil +} + +func (locationsRclone0 *LocationsRclone) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsRcloneSpaceLocationsSpace0(ctx, exec, 1, locationsRclone0, locationsSpace1) + if err != nil { + return err + } + + locationsRclone0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsRclone = locationsRclone0 + + return nil +} + +type locationsRcloneWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + RemoteName mysql.WhereMod[Q, string] + Container mysql.WhereMod[Q, string] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsRcloneWhere[Q]) AliasedAs(alias string) locationsRcloneWhere[Q] { + return buildLocationsRcloneWhere[Q](buildLocationsRcloneColumns(alias)) +} + +func buildLocationsRcloneWhere[Q mysql.Filterable](cols locationsRcloneColumns) locationsRcloneWhere[Q] { + return locationsRcloneWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + RemoteName: mysql.Where[Q, string](cols.RemoteName), + Container: mysql.Where[Q, string](cols.Container), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsRclone) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsRclone cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsRclone = o + } + return nil + default: + return fmt.Errorf("locationsRclone has no relationship %q", name) + } +} + +type locationsRclonePreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsRclonePreloader() locationsRclonePreloader { + return locationsRclonePreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsRclones, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsRcloneThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsRcloneThenLoader[Q orm.Loadable]() locationsRcloneThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsRcloneThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsRclone's SpaceLocationsSpace into the .R struct +func (o *LocationsRclone) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsRclone = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsRclone's SpaceLocationsSpace into the .R struct +func (os LocationsRcloneSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsRclone = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsRcloneJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsRcloneJoins[Q]) aliasedAs(alias string) locationsRcloneJoins[Q] { + return buildLocationsRcloneJoins[Q](buildLocationsRcloneColumns(alias), j.typ) +} + +func buildLocationsRcloneJoins[Q dialect.Joinable](cols locationsRcloneColumns, typ string) locationsRcloneJoins[Q] { + return locationsRcloneJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_s3.bob.go b/database/storage_service/models/locations_s3.bob.go new file mode 100644 index 0000000..db21d99 --- /dev/null +++ b/database/storage_service/models/locations_s3.bob.go @@ -0,0 +1,712 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsS3 is an object representing the database table. +type LocationsS3 struct { + ID int32 `db:"id,pk,autoincr" ` + EndpointURL string `db:"endpoint_url" ` + AccessKeyID string `db:"access_key_id" ` + SecretAccessKey string `db:"secret_access_key" ` + Region string `db:"region" ` + SpaceID string `db:"space_id" ` + Bucket string `db:"bucket" ` + + R locationsS3R `db:"-" ` +} + +// LocationsS3Slice is an alias for a slice of pointers to LocationsS3. +// This should almost always be used instead of []*LocationsS3. +type LocationsS3Slice []*LocationsS3 + +// LocationsS3S contains methods to work with the locations_s3 table +var LocationsS3S = mysql.NewTablex[*LocationsS3, LocationsS3Slice, *LocationsS3Setter]("locations_s3", buildLocationsS3Columns("locations_s3"), []string{"id"}, []string{"space_id"}) + +// LocationsS3SQuery is a query on the locations_s3 table +type LocationsS3SQuery = *mysql.ViewQuery[*LocationsS3, LocationsS3Slice] + +// locationsS3R is where relationships are stored. +type locationsS3R struct { + SpaceLocationsSpace *LocationsSpace // locations_s3_space_id_d8fc3ba3_fk_locations_space_uuid +} + +func buildLocationsS3Columns(alias string) locationsS3Columns { + return locationsS3Columns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "endpoint_url", "access_key_id", "secret_access_key", "region", "space_id", "bucket", + ).WithParent("locations_s3"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + EndpointURL: mysql.Quote(alias, "endpoint_url"), + AccessKeyID: mysql.Quote(alias, "access_key_id"), + SecretAccessKey: mysql.Quote(alias, "secret_access_key"), + Region: mysql.Quote(alias, "region"), + SpaceID: mysql.Quote(alias, "space_id"), + Bucket: mysql.Quote(alias, "bucket"), + } +} + +type locationsS3Columns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + EndpointURL mysql.Expression + AccessKeyID mysql.Expression + SecretAccessKey mysql.Expression + Region mysql.Expression + SpaceID mysql.Expression + Bucket mysql.Expression +} + +func (c locationsS3Columns) Alias() string { + return c.tableAlias +} + +func (locationsS3Columns) AliasedAs(alias string) locationsS3Columns { + return buildLocationsS3Columns(alias) +} + +// LocationsS3Setter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsS3Setter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + EndpointURL omit.Val[string] `db:"endpoint_url" ` + AccessKeyID omit.Val[string] `db:"access_key_id" ` + SecretAccessKey omit.Val[string] `db:"secret_access_key" ` + Region omit.Val[string] `db:"region" ` + SpaceID omit.Val[string] `db:"space_id" ` + Bucket omit.Val[string] `db:"bucket" ` +} + +func (s LocationsS3Setter) SetColumns() []string { + vals := make([]string, 0, 7) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.EndpointURL.IsValue() { + vals = append(vals, "endpoint_url") + } + if s.AccessKeyID.IsValue() { + vals = append(vals, "access_key_id") + } + if s.SecretAccessKey.IsValue() { + vals = append(vals, "secret_access_key") + } + if s.Region.IsValue() { + vals = append(vals, "region") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + if s.Bucket.IsValue() { + vals = append(vals, "bucket") + } + return vals +} + +func (s LocationsS3Setter) Overwrite(t *LocationsS3) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.EndpointURL.IsValue() { + t.EndpointURL = s.EndpointURL.MustGet() + } + if s.AccessKeyID.IsValue() { + t.AccessKeyID = s.AccessKeyID.MustGet() + } + if s.SecretAccessKey.IsValue() { + t.SecretAccessKey = s.SecretAccessKey.MustGet() + } + if s.Region.IsValue() { + t.Region = s.Region.MustGet() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } + if s.Bucket.IsValue() { + t.Bucket = s.Bucket.MustGet() + } +} + +func (s *LocationsS3Setter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsS3S.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.EndpointURL.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.EndpointURL.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AccessKeyID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AccessKeyID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SecretAccessKey.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SecretAccessKey.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Region.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Region.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Bucket.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Bucket.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsS3Setter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_s3")...) +} + +func (s LocationsS3Setter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 7) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.EndpointURL.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "endpoint_url")...), + mysql.Arg(s.EndpointURL), + }}) + } + + if s.AccessKeyID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "access_key_id")...), + mysql.Arg(s.AccessKeyID), + }}) + } + + if s.SecretAccessKey.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "secret_access_key")...), + mysql.Arg(s.SecretAccessKey), + }}) + } + + if s.Region.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "region")...), + mysql.Arg(s.Region), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + if s.Bucket.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "bucket")...), + mysql.Arg(s.Bucket), + }}) + } + + return exprs +} + +// FindLocationsS3 retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsS3(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsS3, error) { + if len(cols) == 0 { + return LocationsS3S.Query( + sm.Where(LocationsS3S.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsS3S.Query( + sm.Where(LocationsS3S.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsS3S.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsS3Exists checks the presence of a single record by primary key +func LocationsS3Exists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsS3S.Query( + sm.Where(LocationsS3S.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsS3 is retrieved from the database +func (o *LocationsS3) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsS3S.AfterSelectHooks.RunHooks(ctx, exec, LocationsS3Slice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsS3S.AfterInsertHooks.RunHooks(ctx, exec, LocationsS3Slice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsS3S.AfterUpdateHooks.RunHooks(ctx, exec, LocationsS3Slice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsS3S.AfterDeleteHooks.RunHooks(ctx, exec, LocationsS3Slice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsS3 +func (o *LocationsS3) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsS3) pkEQ() dialect.Expression { + return mysql.Quote("locations_s3", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsS3 +func (o *LocationsS3) Update(ctx context.Context, exec bob.Executor, s *LocationsS3Setter) error { + _, err := LocationsS3S.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsS3 record with an executor +func (o *LocationsS3) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsS3S.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsS3 using the executor +func (o *LocationsS3) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsS3S.Query( + sm.Where(LocationsS3S.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsS3Slice is retrieved from the database +func (o LocationsS3Slice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsS3S.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsS3S.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsS3S.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsS3S.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsS3Slice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_s3", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsS3Slice) copyMatchingRows(from ...*LocationsS3) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsS3Slice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsS3S.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsS3: + o.copyMatchingRows(retrieved) + case []*LocationsS3: + o.copyMatchingRows(retrieved...) + case LocationsS3Slice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsS3 or a slice of LocationsS3 + // then run the AfterUpdateHooks on the slice + _, err = LocationsS3S.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsS3Slice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsS3S.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsS3: + o.copyMatchingRows(retrieved) + case []*LocationsS3: + o.copyMatchingRows(retrieved...) + case LocationsS3Slice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsS3 or a slice of LocationsS3 + // then run the AfterDeleteHooks on the slice + _, err = LocationsS3S.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsS3Slice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsS3Setter) error { + _, err := LocationsS3S.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsS3Slice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsS3S.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsS3Slice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsS3S.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsS3) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsS3Slice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsS3SpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsS30 *LocationsS3, locationsSpace1 *LocationsSpace) (*LocationsS3, error) { + setter := &LocationsS3Setter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsS30.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsS3SpaceLocationsSpace0: %w", err) + } + + return locationsS30, nil +} + +func (locationsS30 *LocationsS3) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsS3SpaceLocationsSpace0(ctx, exec, 1, locationsS30, locationsSpace1) + if err != nil { + return err + } + + locationsS30.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsS3 = locationsS30 + + return nil +} + +func (locationsS30 *LocationsS3) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsS3SpaceLocationsSpace0(ctx, exec, 1, locationsS30, locationsSpace1) + if err != nil { + return err + } + + locationsS30.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsS3 = locationsS30 + + return nil +} + +type locationsS3Where[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + EndpointURL mysql.WhereMod[Q, string] + AccessKeyID mysql.WhereMod[Q, string] + SecretAccessKey mysql.WhereMod[Q, string] + Region mysql.WhereMod[Q, string] + SpaceID mysql.WhereMod[Q, string] + Bucket mysql.WhereMod[Q, string] +} + +func (locationsS3Where[Q]) AliasedAs(alias string) locationsS3Where[Q] { + return buildLocationsS3Where[Q](buildLocationsS3Columns(alias)) +} + +func buildLocationsS3Where[Q mysql.Filterable](cols locationsS3Columns) locationsS3Where[Q] { + return locationsS3Where[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + EndpointURL: mysql.Where[Q, string](cols.EndpointURL), + AccessKeyID: mysql.Where[Q, string](cols.AccessKeyID), + SecretAccessKey: mysql.Where[Q, string](cols.SecretAccessKey), + Region: mysql.Where[Q, string](cols.Region), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + Bucket: mysql.Where[Q, string](cols.Bucket), + } +} + +func (o *LocationsS3) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsS3 cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsS3 = o + } + return nil + default: + return fmt.Errorf("locationsS3 has no relationship %q", name) + } +} + +type locationsS3Preloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsS3Preloader() locationsS3Preloader { + return locationsS3Preloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsS3S, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsS3ThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsS3ThenLoader[Q orm.Loadable]() locationsS3ThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsS3ThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsS3's SpaceLocationsSpace into the .R struct +func (o *LocationsS3) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsS3 = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsS3's SpaceLocationsSpace into the .R struct +func (os LocationsS3Slice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsS3 = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsS3Joins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsS3Joins[Q]) aliasedAs(alias string) locationsS3Joins[Q] { + return buildLocationsS3Joins[Q](buildLocationsS3Columns(alias), j.typ) +} + +func buildLocationsS3Joins[Q dialect.Joinable](cols locationsS3Columns, typ string) locationsS3Joins[Q] { + return locationsS3Joins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_space.bob.go b/database/storage_service/models/locations_space.bob.go new file mode 100644 index 0000000..da5716d --- /dev/null +++ b/database/storage_service/models/locations_space.bob.go @@ -0,0 +1,3612 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsSpace is an object representing the database table. +type LocationsSpace struct { + ID int32 `db:"id,pk,autoincr" ` + UUID string `db:"uuid" ` + AccessProtocol string `db:"access_protocol" ` + Size null.Val[int64] `db:"size" ` + Used int64 `db:"used" ` + Path string `db:"path" ` + Verified bool `db:"verified" ` + LastVerified null.Val[time.Time] `db:"last_verified" ` + StagingPath string `db:"staging_path" ` + + R locationsSpaceR `db:"-" ` +} + +// LocationsSpaceSlice is an alias for a slice of pointers to LocationsSpace. +// This should almost always be used instead of []*LocationsSpace. +type LocationsSpaceSlice []*LocationsSpace + +// LocationsSpaces contains methods to work with the locations_space table +var LocationsSpaces = mysql.NewTablex[*LocationsSpace, LocationsSpaceSlice, *LocationsSpaceSetter]("locations_space", buildLocationsSpaceColumns("locations_space"), []string{"id"}, []string{"uuid"}) + +// LocationsSpacesQuery is a query on the locations_space table +type LocationsSpacesQuery = *mysql.ViewQuery[*LocationsSpace, LocationsSpaceSlice] + +// locationsSpaceR is where relationships are stored. +type locationsSpaceR struct { + SpaceLocationsArchipelago *LocationsArchipelago // locations_archipelago_space_id_be47fd5c_fk_locations_space_uuid + SpaceLocationsArkivum *LocationsArkivum // locations_arkivum_space_id_d159e309_fk_locations_space_uuid + SpaceLocationsDataverse *LocationsDataverse // locations_dataverse_space_id_1b94d732_fk_locations_space_uuid + SpaceLocationsDspace *LocationsDspace // locations_dspace_space_id_e1c12ce1_fk_locations_space_uuid + SpaceLocationsDspacerest *LocationsDspacerest // locations_dspacerest_space_id_6ae6a82b_fk_locations_space_uuid + SpaceLocationsDuracloud *LocationsDuracloud // locations_duracloud_space_id_753df0f2_fk_locations_space_uuid + SpaceLocationsFedora *LocationsFedora // locations_fedora_space_id_088fe895_fk_locations_space_uuid + SpaceLocationsGPG *LocationsGPG // locations_gpg_space_id_6223440d_fk_locations_space_uuid + SpaceLocationsLocalfilesystem *LocationsLocalfilesystem // locations_localfiles_space_id_a97d3d9f_fk_locations + SpaceLocationsLocations LocationsLocationSlice // locations_location_space_id_748845a7_fk_locations_space_uuid + SpaceLocationsLockssomatic *LocationsLockssomatic // locations_lockssomatic_space_id_cc6a3cd6_fk_locations_space_uuid + SpaceLocationsNF *LocationsNF // locations_nfs_space_id_34913c3b_fk_locations_space_uuid + SpaceLocationsOfflinereplicastaging *LocationsOfflinereplicastaging // locations_offlinerep_space_id_2a8d7578_fk_locations + SpaceLocationsPipelinelocalf *LocationsPipelinelocalf // locations_pipelinelo_space_id_6f6ba9f6_fk_locations + SpaceLocationsRclone *LocationsRclone // locations_rclone_space_id_adb7fd1d_fk_locations_space_uuid + SpaceLocationsS3 *LocationsS3 // locations_s3_space_id_d8fc3ba3_fk_locations_space_uuid + SpaceLocationsSwift *LocationsSwift // locations_swift_space_id_9cfded49_fk_locations_space_uuid +} + +func buildLocationsSpaceColumns(alias string) locationsSpaceColumns { + return locationsSpaceColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "uuid", "access_protocol", "size", "used", "path", "verified", "last_verified", "staging_path", + ).WithParent("locations_space"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + UUID: mysql.Quote(alias, "uuid"), + AccessProtocol: mysql.Quote(alias, "access_protocol"), + Size: mysql.Quote(alias, "size"), + Used: mysql.Quote(alias, "used"), + Path: mysql.Quote(alias, "path"), + Verified: mysql.Quote(alias, "verified"), + LastVerified: mysql.Quote(alias, "last_verified"), + StagingPath: mysql.Quote(alias, "staging_path"), + } +} + +type locationsSpaceColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + UUID mysql.Expression + AccessProtocol mysql.Expression + Size mysql.Expression + Used mysql.Expression + Path mysql.Expression + Verified mysql.Expression + LastVerified mysql.Expression + StagingPath mysql.Expression +} + +func (c locationsSpaceColumns) Alias() string { + return c.tableAlias +} + +func (locationsSpaceColumns) AliasedAs(alias string) locationsSpaceColumns { + return buildLocationsSpaceColumns(alias) +} + +// LocationsSpaceSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsSpaceSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + UUID omit.Val[string] `db:"uuid" ` + AccessProtocol omit.Val[string] `db:"access_protocol" ` + Size omitnull.Val[int64] `db:"size" ` + Used omit.Val[int64] `db:"used" ` + Path omit.Val[string] `db:"path" ` + Verified omit.Val[bool] `db:"verified" ` + LastVerified omitnull.Val[time.Time] `db:"last_verified" ` + StagingPath omit.Val[string] `db:"staging_path" ` +} + +func (s LocationsSpaceSetter) SetColumns() []string { + vals := make([]string, 0, 9) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.UUID.IsValue() { + vals = append(vals, "uuid") + } + if s.AccessProtocol.IsValue() { + vals = append(vals, "access_protocol") + } + if !s.Size.IsUnset() { + vals = append(vals, "size") + } + if s.Used.IsValue() { + vals = append(vals, "used") + } + if s.Path.IsValue() { + vals = append(vals, "path") + } + if s.Verified.IsValue() { + vals = append(vals, "verified") + } + if !s.LastVerified.IsUnset() { + vals = append(vals, "last_verified") + } + if s.StagingPath.IsValue() { + vals = append(vals, "staging_path") + } + return vals +} + +func (s LocationsSpaceSetter) Overwrite(t *LocationsSpace) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.UUID.IsValue() { + t.UUID = s.UUID.MustGet() + } + if s.AccessProtocol.IsValue() { + t.AccessProtocol = s.AccessProtocol.MustGet() + } + if !s.Size.IsUnset() { + t.Size = s.Size.MustGetNull() + } + if s.Used.IsValue() { + t.Used = s.Used.MustGet() + } + if s.Path.IsValue() { + t.Path = s.Path.MustGet() + } + if s.Verified.IsValue() { + t.Verified = s.Verified.MustGet() + } + if !s.LastVerified.IsUnset() { + t.LastVerified = s.LastVerified.MustGetNull() + } + if s.StagingPath.IsValue() { + t.StagingPath = s.StagingPath.MustGet() + } +} + +func (s *LocationsSpaceSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsSpaces.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UUID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UUID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AccessProtocol.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AccessProtocol.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Size.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Size.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Used.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Used.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Path.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Path.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Verified.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Verified.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.LastVerified.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.LastVerified.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.StagingPath.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.StagingPath.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsSpaceSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_space")...) +} + +func (s LocationsSpaceSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 9) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.UUID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "uuid")...), + mysql.Arg(s.UUID), + }}) + } + + if s.AccessProtocol.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "access_protocol")...), + mysql.Arg(s.AccessProtocol), + }}) + } + + if !s.Size.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "size")...), + mysql.Arg(s.Size), + }}) + } + + if s.Used.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "used")...), + mysql.Arg(s.Used), + }}) + } + + if s.Path.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "path")...), + mysql.Arg(s.Path), + }}) + } + + if s.Verified.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "verified")...), + mysql.Arg(s.Verified), + }}) + } + + if !s.LastVerified.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "last_verified")...), + mysql.Arg(s.LastVerified), + }}) + } + + if s.StagingPath.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "staging_path")...), + mysql.Arg(s.StagingPath), + }}) + } + + return exprs +} + +// FindLocationsSpace retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsSpace(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsSpace, error) { + if len(cols) == 0 { + return LocationsSpaces.Query( + sm.Where(LocationsSpaces.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsSpaces.Query( + sm.Where(LocationsSpaces.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsSpaces.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsSpaceExists checks the presence of a single record by primary key +func LocationsSpaceExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsSpaces.Query( + sm.Where(LocationsSpaces.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsSpace is retrieved from the database +func (o *LocationsSpace) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsSpaces.AfterSelectHooks.RunHooks(ctx, exec, LocationsSpaceSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsSpaces.AfterInsertHooks.RunHooks(ctx, exec, LocationsSpaceSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsSpaces.AfterUpdateHooks.RunHooks(ctx, exec, LocationsSpaceSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsSpaces.AfterDeleteHooks.RunHooks(ctx, exec, LocationsSpaceSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsSpace +func (o *LocationsSpace) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsSpace) pkEQ() dialect.Expression { + return mysql.Quote("locations_space", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsSpace +func (o *LocationsSpace) Update(ctx context.Context, exec bob.Executor, s *LocationsSpaceSetter) error { + _, err := LocationsSpaces.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsSpace record with an executor +func (o *LocationsSpace) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsSpaces.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsSpace using the executor +func (o *LocationsSpace) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsSpaces.Query( + sm.Where(LocationsSpaces.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsSpaceSlice is retrieved from the database +func (o LocationsSpaceSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsSpaces.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsSpaces.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsSpaces.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsSpaces.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsSpaceSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_space", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsSpaceSlice) copyMatchingRows(from ...*LocationsSpace) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsSpaceSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsSpaces.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsSpace: + o.copyMatchingRows(retrieved) + case []*LocationsSpace: + o.copyMatchingRows(retrieved...) + case LocationsSpaceSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsSpace or a slice of LocationsSpace + // then run the AfterUpdateHooks on the slice + _, err = LocationsSpaces.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsSpaceSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsSpaces.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsSpace: + o.copyMatchingRows(retrieved) + case []*LocationsSpace: + o.copyMatchingRows(retrieved...) + case LocationsSpaceSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsSpace or a slice of LocationsSpace + // then run the AfterDeleteHooks on the slice + _, err = LocationsSpaces.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsSpaceSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsSpaceSetter) error { + _, err := LocationsSpaces.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsSpaceSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsSpaces.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsSpaceSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsSpaces.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsArchipelago starts a query for related objects on locations_archipelago +func (o *LocationsSpace) SpaceLocationsArchipelago(mods ...bob.Mod[*dialect.SelectQuery]) LocationsArchipelagosQuery { + return LocationsArchipelagos.Query(append(mods, + sm.Where(LocationsArchipelagos.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsArchipelago(mods ...bob.Mod[*dialect.SelectQuery]) LocationsArchipelagosQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsArchipelagos.Query(append(mods, + sm.Where(mysql.Group(LocationsArchipelagos.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsArkivum starts a query for related objects on locations_arkivum +func (o *LocationsSpace) SpaceLocationsArkivum(mods ...bob.Mod[*dialect.SelectQuery]) LocationsArkivumsQuery { + return LocationsArkivums.Query(append(mods, + sm.Where(LocationsArkivums.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsArkivum(mods ...bob.Mod[*dialect.SelectQuery]) LocationsArkivumsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsArkivums.Query(append(mods, + sm.Where(mysql.Group(LocationsArkivums.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsDataverse starts a query for related objects on locations_dataverse +func (o *LocationsSpace) SpaceLocationsDataverse(mods ...bob.Mod[*dialect.SelectQuery]) LocationsDataversesQuery { + return LocationsDataverses.Query(append(mods, + sm.Where(LocationsDataverses.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsDataverse(mods ...bob.Mod[*dialect.SelectQuery]) LocationsDataversesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsDataverses.Query(append(mods, + sm.Where(mysql.Group(LocationsDataverses.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsDspace starts a query for related objects on locations_dspace +func (o *LocationsSpace) SpaceLocationsDspace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsDspacesQuery { + return LocationsDspaces.Query(append(mods, + sm.Where(LocationsDspaces.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsDspace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsDspacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsDspaces.Query(append(mods, + sm.Where(mysql.Group(LocationsDspaces.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsDspacerest starts a query for related objects on locations_dspacerest +func (o *LocationsSpace) SpaceLocationsDspacerest(mods ...bob.Mod[*dialect.SelectQuery]) LocationsDspacerestsQuery { + return LocationsDspacerests.Query(append(mods, + sm.Where(LocationsDspacerests.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsDspacerest(mods ...bob.Mod[*dialect.SelectQuery]) LocationsDspacerestsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsDspacerests.Query(append(mods, + sm.Where(mysql.Group(LocationsDspacerests.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsDuracloud starts a query for related objects on locations_duracloud +func (o *LocationsSpace) SpaceLocationsDuracloud(mods ...bob.Mod[*dialect.SelectQuery]) LocationsDuracloudsQuery { + return LocationsDuraclouds.Query(append(mods, + sm.Where(LocationsDuraclouds.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsDuracloud(mods ...bob.Mod[*dialect.SelectQuery]) LocationsDuracloudsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsDuraclouds.Query(append(mods, + sm.Where(mysql.Group(LocationsDuraclouds.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsFedora starts a query for related objects on locations_fedora +func (o *LocationsSpace) SpaceLocationsFedora(mods ...bob.Mod[*dialect.SelectQuery]) LocationsFedorasQuery { + return LocationsFedoras.Query(append(mods, + sm.Where(LocationsFedoras.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsFedora(mods ...bob.Mod[*dialect.SelectQuery]) LocationsFedorasQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsFedoras.Query(append(mods, + sm.Where(mysql.Group(LocationsFedoras.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsGPG starts a query for related objects on locations_gpg +func (o *LocationsSpace) SpaceLocationsGPG(mods ...bob.Mod[*dialect.SelectQuery]) LocationsGPGSQuery { + return LocationsGPGS.Query(append(mods, + sm.Where(LocationsGPGS.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsGPG(mods ...bob.Mod[*dialect.SelectQuery]) LocationsGPGSQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsGPGS.Query(append(mods, + sm.Where(mysql.Group(LocationsGPGS.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsLocalfilesystem starts a query for related objects on locations_localfilesystem +func (o *LocationsSpace) SpaceLocationsLocalfilesystem(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocalfilesystemsQuery { + return LocationsLocalfilesystems.Query(append(mods, + sm.Where(LocationsLocalfilesystems.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsLocalfilesystem(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocalfilesystemsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocalfilesystems.Query(append(mods, + sm.Where(mysql.Group(LocationsLocalfilesystems.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsLocations starts a query for related objects on locations_location +func (o *LocationsSpace) SpaceLocationsLocations(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + return LocationsLocations.Query(append(mods, + sm.Where(LocationsLocations.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsLocations(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLocationsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLocations.Query(append(mods, + sm.Where(mysql.Group(LocationsLocations.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsLockssomatic starts a query for related objects on locations_lockssomatic +func (o *LocationsSpace) SpaceLocationsLockssomatic(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLockssomaticsQuery { + return LocationsLockssomatics.Query(append(mods, + sm.Where(LocationsLockssomatics.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsLockssomatic(mods ...bob.Mod[*dialect.SelectQuery]) LocationsLockssomaticsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsLockssomatics.Query(append(mods, + sm.Where(mysql.Group(LocationsLockssomatics.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsNF starts a query for related objects on locations_nfs +func (o *LocationsSpace) SpaceLocationsNF(mods ...bob.Mod[*dialect.SelectQuery]) LocationsNFSQuery { + return LocationsNFS.Query(append(mods, + sm.Where(LocationsNFS.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsNF(mods ...bob.Mod[*dialect.SelectQuery]) LocationsNFSQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsNFS.Query(append(mods, + sm.Where(mysql.Group(LocationsNFS.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsOfflinereplicastaging starts a query for related objects on locations_offlinereplicastaging +func (o *LocationsSpace) SpaceLocationsOfflinereplicastaging(mods ...bob.Mod[*dialect.SelectQuery]) LocationsOfflinereplicastagingsQuery { + return LocationsOfflinereplicastagings.Query(append(mods, + sm.Where(LocationsOfflinereplicastagings.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsOfflinereplicastaging(mods ...bob.Mod[*dialect.SelectQuery]) LocationsOfflinereplicastagingsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsOfflinereplicastagings.Query(append(mods, + sm.Where(mysql.Group(LocationsOfflinereplicastagings.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsPipelinelocalf starts a query for related objects on locations_pipelinelocalfs +func (o *LocationsSpace) SpaceLocationsPipelinelocalf(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPipelinelocalfsQuery { + return LocationsPipelinelocalfs.Query(append(mods, + sm.Where(LocationsPipelinelocalfs.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsPipelinelocalf(mods ...bob.Mod[*dialect.SelectQuery]) LocationsPipelinelocalfsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsPipelinelocalfs.Query(append(mods, + sm.Where(mysql.Group(LocationsPipelinelocalfs.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsRclone starts a query for related objects on locations_rclone +func (o *LocationsSpace) SpaceLocationsRclone(mods ...bob.Mod[*dialect.SelectQuery]) LocationsRclonesQuery { + return LocationsRclones.Query(append(mods, + sm.Where(LocationsRclones.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsRclone(mods ...bob.Mod[*dialect.SelectQuery]) LocationsRclonesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsRclones.Query(append(mods, + sm.Where(mysql.Group(LocationsRclones.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsS3 starts a query for related objects on locations_s3 +func (o *LocationsSpace) SpaceLocationsS3(mods ...bob.Mod[*dialect.SelectQuery]) LocationsS3SQuery { + return LocationsS3S.Query(append(mods, + sm.Where(LocationsS3S.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsS3(mods ...bob.Mod[*dialect.SelectQuery]) LocationsS3SQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsS3S.Query(append(mods, + sm.Where(mysql.Group(LocationsS3S.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +// SpaceLocationsSwift starts a query for related objects on locations_swift +func (o *LocationsSpace) SpaceLocationsSwift(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSwiftsQuery { + return LocationsSwifts.Query(append(mods, + sm.Where(LocationsSwifts.Columns.SpaceID.EQ(mysql.Arg(o.UUID))), + )...) +} + +func (os LocationsSpaceSlice) SpaceLocationsSwift(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSwiftsQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UUID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSwifts.Query(append(mods, + sm.Where(mysql.Group(LocationsSwifts.Columns.SpaceID).OP("IN", PKArgExpr)), + )...) +} + +func insertLocationsSpaceSpaceLocationsArchipelago0(ctx context.Context, exec bob.Executor, locationsArchipelago1 *LocationsArchipelagoSetter, locationsSpace0 *LocationsSpace) (*LocationsArchipelago, error) { + locationsArchipelago1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsArchipelagos.Insert(locationsArchipelago1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsArchipelago0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsArchipelago0(ctx context.Context, exec bob.Executor, count int, locationsArchipelago1 *LocationsArchipelago, locationsSpace0 *LocationsSpace) (*LocationsArchipelago, error) { + setter := &LocationsArchipelagoSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsArchipelago1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsArchipelago0: %w", err) + } + + return locationsArchipelago1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsArchipelago(ctx context.Context, exec bob.Executor, related *LocationsArchipelagoSetter) error { + var err error + + locationsArchipelago1, err := insertLocationsSpaceSpaceLocationsArchipelago0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsArchipelago = locationsArchipelago1 + + locationsArchipelago1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsArchipelago(ctx context.Context, exec bob.Executor, locationsArchipelago1 *LocationsArchipelago) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsArchipelago0(ctx, exec, 1, locationsArchipelago1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsArchipelago = locationsArchipelago1 + + locationsArchipelago1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsArkivum0(ctx context.Context, exec bob.Executor, locationsArkivum1 *LocationsArkivumSetter, locationsSpace0 *LocationsSpace) (*LocationsArkivum, error) { + locationsArkivum1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsArkivums.Insert(locationsArkivum1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsArkivum0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsArkivum0(ctx context.Context, exec bob.Executor, count int, locationsArkivum1 *LocationsArkivum, locationsSpace0 *LocationsSpace) (*LocationsArkivum, error) { + setter := &LocationsArkivumSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsArkivum1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsArkivum0: %w", err) + } + + return locationsArkivum1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsArkivum(ctx context.Context, exec bob.Executor, related *LocationsArkivumSetter) error { + var err error + + locationsArkivum1, err := insertLocationsSpaceSpaceLocationsArkivum0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsArkivum = locationsArkivum1 + + locationsArkivum1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsArkivum(ctx context.Context, exec bob.Executor, locationsArkivum1 *LocationsArkivum) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsArkivum0(ctx, exec, 1, locationsArkivum1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsArkivum = locationsArkivum1 + + locationsArkivum1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsDataverse0(ctx context.Context, exec bob.Executor, locationsDataverse1 *LocationsDataverseSetter, locationsSpace0 *LocationsSpace) (*LocationsDataverse, error) { + locationsDataverse1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsDataverses.Insert(locationsDataverse1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsDataverse0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsDataverse0(ctx context.Context, exec bob.Executor, count int, locationsDataverse1 *LocationsDataverse, locationsSpace0 *LocationsSpace) (*LocationsDataverse, error) { + setter := &LocationsDataverseSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsDataverse1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsDataverse0: %w", err) + } + + return locationsDataverse1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsDataverse(ctx context.Context, exec bob.Executor, related *LocationsDataverseSetter) error { + var err error + + locationsDataverse1, err := insertLocationsSpaceSpaceLocationsDataverse0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsDataverse = locationsDataverse1 + + locationsDataverse1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsDataverse(ctx context.Context, exec bob.Executor, locationsDataverse1 *LocationsDataverse) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsDataverse0(ctx, exec, 1, locationsDataverse1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsDataverse = locationsDataverse1 + + locationsDataverse1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsDspace0(ctx context.Context, exec bob.Executor, locationsDspace1 *LocationsDspaceSetter, locationsSpace0 *LocationsSpace) (*LocationsDspace, error) { + locationsDspace1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsDspaces.Insert(locationsDspace1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsDspace0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsDspace0(ctx context.Context, exec bob.Executor, count int, locationsDspace1 *LocationsDspace, locationsSpace0 *LocationsSpace) (*LocationsDspace, error) { + setter := &LocationsDspaceSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsDspace1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsDspace0: %w", err) + } + + return locationsDspace1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsDspace(ctx context.Context, exec bob.Executor, related *LocationsDspaceSetter) error { + var err error + + locationsDspace1, err := insertLocationsSpaceSpaceLocationsDspace0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsDspace = locationsDspace1 + + locationsDspace1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsDspace(ctx context.Context, exec bob.Executor, locationsDspace1 *LocationsDspace) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsDspace0(ctx, exec, 1, locationsDspace1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsDspace = locationsDspace1 + + locationsDspace1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsDspacerest0(ctx context.Context, exec bob.Executor, locationsDspacerest1 *LocationsDspacerestSetter, locationsSpace0 *LocationsSpace) (*LocationsDspacerest, error) { + locationsDspacerest1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsDspacerests.Insert(locationsDspacerest1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsDspacerest0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsDspacerest0(ctx context.Context, exec bob.Executor, count int, locationsDspacerest1 *LocationsDspacerest, locationsSpace0 *LocationsSpace) (*LocationsDspacerest, error) { + setter := &LocationsDspacerestSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsDspacerest1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsDspacerest0: %w", err) + } + + return locationsDspacerest1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsDspacerest(ctx context.Context, exec bob.Executor, related *LocationsDspacerestSetter) error { + var err error + + locationsDspacerest1, err := insertLocationsSpaceSpaceLocationsDspacerest0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsDspacerest = locationsDspacerest1 + + locationsDspacerest1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsDspacerest(ctx context.Context, exec bob.Executor, locationsDspacerest1 *LocationsDspacerest) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsDspacerest0(ctx, exec, 1, locationsDspacerest1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsDspacerest = locationsDspacerest1 + + locationsDspacerest1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsDuracloud0(ctx context.Context, exec bob.Executor, locationsDuracloud1 *LocationsDuracloudSetter, locationsSpace0 *LocationsSpace) (*LocationsDuracloud, error) { + locationsDuracloud1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsDuraclouds.Insert(locationsDuracloud1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsDuracloud0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsDuracloud0(ctx context.Context, exec bob.Executor, count int, locationsDuracloud1 *LocationsDuracloud, locationsSpace0 *LocationsSpace) (*LocationsDuracloud, error) { + setter := &LocationsDuracloudSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsDuracloud1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsDuracloud0: %w", err) + } + + return locationsDuracloud1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsDuracloud(ctx context.Context, exec bob.Executor, related *LocationsDuracloudSetter) error { + var err error + + locationsDuracloud1, err := insertLocationsSpaceSpaceLocationsDuracloud0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsDuracloud = locationsDuracloud1 + + locationsDuracloud1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsDuracloud(ctx context.Context, exec bob.Executor, locationsDuracloud1 *LocationsDuracloud) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsDuracloud0(ctx, exec, 1, locationsDuracloud1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsDuracloud = locationsDuracloud1 + + locationsDuracloud1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsFedora0(ctx context.Context, exec bob.Executor, locationsFedora1 *LocationsFedoraSetter, locationsSpace0 *LocationsSpace) (*LocationsFedora, error) { + locationsFedora1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsFedoras.Insert(locationsFedora1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsFedora0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsFedora0(ctx context.Context, exec bob.Executor, count int, locationsFedora1 *LocationsFedora, locationsSpace0 *LocationsSpace) (*LocationsFedora, error) { + setter := &LocationsFedoraSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsFedora1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsFedora0: %w", err) + } + + return locationsFedora1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsFedora(ctx context.Context, exec bob.Executor, related *LocationsFedoraSetter) error { + var err error + + locationsFedora1, err := insertLocationsSpaceSpaceLocationsFedora0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsFedora = locationsFedora1 + + locationsFedora1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsFedora(ctx context.Context, exec bob.Executor, locationsFedora1 *LocationsFedora) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsFedora0(ctx, exec, 1, locationsFedora1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsFedora = locationsFedora1 + + locationsFedora1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsGPG0(ctx context.Context, exec bob.Executor, locationsGPG1 *LocationsGPGSetter, locationsSpace0 *LocationsSpace) (*LocationsGPG, error) { + locationsGPG1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsGPGS.Insert(locationsGPG1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsGPG0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsGPG0(ctx context.Context, exec bob.Executor, count int, locationsGPG1 *LocationsGPG, locationsSpace0 *LocationsSpace) (*LocationsGPG, error) { + setter := &LocationsGPGSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsGPG1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsGPG0: %w", err) + } + + return locationsGPG1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsGPG(ctx context.Context, exec bob.Executor, related *LocationsGPGSetter) error { + var err error + + locationsGPG1, err := insertLocationsSpaceSpaceLocationsGPG0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsGPG = locationsGPG1 + + locationsGPG1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsGPG(ctx context.Context, exec bob.Executor, locationsGPG1 *LocationsGPG) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsGPG0(ctx, exec, 1, locationsGPG1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsGPG = locationsGPG1 + + locationsGPG1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsLocalfilesystem0(ctx context.Context, exec bob.Executor, locationsLocalfilesystem1 *LocationsLocalfilesystemSetter, locationsSpace0 *LocationsSpace) (*LocationsLocalfilesystem, error) { + locationsLocalfilesystem1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsLocalfilesystems.Insert(locationsLocalfilesystem1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsLocalfilesystem0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsLocalfilesystem0(ctx context.Context, exec bob.Executor, count int, locationsLocalfilesystem1 *LocationsLocalfilesystem, locationsSpace0 *LocationsSpace) (*LocationsLocalfilesystem, error) { + setter := &LocationsLocalfilesystemSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsLocalfilesystem1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsLocalfilesystem0: %w", err) + } + + return locationsLocalfilesystem1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsLocalfilesystem(ctx context.Context, exec bob.Executor, related *LocationsLocalfilesystemSetter) error { + var err error + + locationsLocalfilesystem1, err := insertLocationsSpaceSpaceLocationsLocalfilesystem0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsLocalfilesystem = locationsLocalfilesystem1 + + locationsLocalfilesystem1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsLocalfilesystem(ctx context.Context, exec bob.Executor, locationsLocalfilesystem1 *LocationsLocalfilesystem) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsLocalfilesystem0(ctx, exec, 1, locationsLocalfilesystem1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsLocalfilesystem = locationsLocalfilesystem1 + + locationsLocalfilesystem1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsLocations0(ctx context.Context, exec bob.Executor, locationsLocations1 []*LocationsLocationSetter, locationsSpace0 *LocationsSpace) (LocationsLocationSlice, error) { + for i := range locationsLocations1 { + locationsLocations1[i].SpaceID = omit.From(locationsSpace0.UUID) + } + + ret, err := LocationsLocations.Insert(bob.ToMods(locationsLocations1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsLocations0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsLocations0(ctx context.Context, exec bob.Executor, count int, locationsLocations1 LocationsLocationSlice, locationsSpace0 *LocationsSpace) (LocationsLocationSlice, error) { + setter := &LocationsLocationSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsLocations1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsLocations0: %w", err) + } + + return locationsLocations1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsLocations(ctx context.Context, exec bob.Executor, related ...*LocationsLocationSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + locationsLocations1, err := insertLocationsSpaceSpaceLocationsLocations0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsLocations = append(locationsSpace0.R.SpaceLocationsLocations, locationsLocations1...) + + for _, rel := range locationsLocations1 { + rel.R.SpaceLocationsSpace = locationsSpace0 + } + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsLocations(ctx context.Context, exec bob.Executor, related ...*LocationsLocation) error { + if len(related) == 0 { + return nil + } + + var err error + locationsLocations1 := LocationsLocationSlice(related) + + _, err = attachLocationsSpaceSpaceLocationsLocations0(ctx, exec, len(related), locationsLocations1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsLocations = append(locationsSpace0.R.SpaceLocationsLocations, locationsLocations1...) + + for _, rel := range related { + rel.R.SpaceLocationsSpace = locationsSpace0 + } + + return nil +} + +func insertLocationsSpaceSpaceLocationsLockssomatic0(ctx context.Context, exec bob.Executor, locationsLockssomatic1 *LocationsLockssomaticSetter, locationsSpace0 *LocationsSpace) (*LocationsLockssomatic, error) { + locationsLockssomatic1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsLockssomatics.Insert(locationsLockssomatic1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsLockssomatic0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsLockssomatic0(ctx context.Context, exec bob.Executor, count int, locationsLockssomatic1 *LocationsLockssomatic, locationsSpace0 *LocationsSpace) (*LocationsLockssomatic, error) { + setter := &LocationsLockssomaticSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsLockssomatic1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsLockssomatic0: %w", err) + } + + return locationsLockssomatic1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsLockssomatic(ctx context.Context, exec bob.Executor, related *LocationsLockssomaticSetter) error { + var err error + + locationsLockssomatic1, err := insertLocationsSpaceSpaceLocationsLockssomatic0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsLockssomatic = locationsLockssomatic1 + + locationsLockssomatic1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsLockssomatic(ctx context.Context, exec bob.Executor, locationsLockssomatic1 *LocationsLockssomatic) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsLockssomatic0(ctx, exec, 1, locationsLockssomatic1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsLockssomatic = locationsLockssomatic1 + + locationsLockssomatic1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsNF0(ctx context.Context, exec bob.Executor, locationsNF1 *LocationsNFSetter, locationsSpace0 *LocationsSpace) (*LocationsNF, error) { + locationsNF1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsNFS.Insert(locationsNF1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsNF0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsNF0(ctx context.Context, exec bob.Executor, count int, locationsNF1 *LocationsNF, locationsSpace0 *LocationsSpace) (*LocationsNF, error) { + setter := &LocationsNFSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsNF1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsNF0: %w", err) + } + + return locationsNF1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsNF(ctx context.Context, exec bob.Executor, related *LocationsNFSetter) error { + var err error + + locationsNF1, err := insertLocationsSpaceSpaceLocationsNF0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsNF = locationsNF1 + + locationsNF1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsNF(ctx context.Context, exec bob.Executor, locationsNF1 *LocationsNF) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsNF0(ctx, exec, 1, locationsNF1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsNF = locationsNF1 + + locationsNF1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsOfflinereplicastaging0(ctx context.Context, exec bob.Executor, locationsOfflinereplicastaging1 *LocationsOfflinereplicastagingSetter, locationsSpace0 *LocationsSpace) (*LocationsOfflinereplicastaging, error) { + locationsOfflinereplicastaging1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsOfflinereplicastagings.Insert(locationsOfflinereplicastaging1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsOfflinereplicastaging0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsOfflinereplicastaging0(ctx context.Context, exec bob.Executor, count int, locationsOfflinereplicastaging1 *LocationsOfflinereplicastaging, locationsSpace0 *LocationsSpace) (*LocationsOfflinereplicastaging, error) { + setter := &LocationsOfflinereplicastagingSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsOfflinereplicastaging1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsOfflinereplicastaging0: %w", err) + } + + return locationsOfflinereplicastaging1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsOfflinereplicastaging(ctx context.Context, exec bob.Executor, related *LocationsOfflinereplicastagingSetter) error { + var err error + + locationsOfflinereplicastaging1, err := insertLocationsSpaceSpaceLocationsOfflinereplicastaging0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsOfflinereplicastaging = locationsOfflinereplicastaging1 + + locationsOfflinereplicastaging1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsOfflinereplicastaging(ctx context.Context, exec bob.Executor, locationsOfflinereplicastaging1 *LocationsOfflinereplicastaging) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsOfflinereplicastaging0(ctx, exec, 1, locationsOfflinereplicastaging1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsOfflinereplicastaging = locationsOfflinereplicastaging1 + + locationsOfflinereplicastaging1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsPipelinelocalf0(ctx context.Context, exec bob.Executor, locationsPipelinelocalf1 *LocationsPipelinelocalfSetter, locationsSpace0 *LocationsSpace) (*LocationsPipelinelocalf, error) { + locationsPipelinelocalf1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsPipelinelocalfs.Insert(locationsPipelinelocalf1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsPipelinelocalf0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsPipelinelocalf0(ctx context.Context, exec bob.Executor, count int, locationsPipelinelocalf1 *LocationsPipelinelocalf, locationsSpace0 *LocationsSpace) (*LocationsPipelinelocalf, error) { + setter := &LocationsPipelinelocalfSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsPipelinelocalf1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsPipelinelocalf0: %w", err) + } + + return locationsPipelinelocalf1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsPipelinelocalf(ctx context.Context, exec bob.Executor, related *LocationsPipelinelocalfSetter) error { + var err error + + locationsPipelinelocalf1, err := insertLocationsSpaceSpaceLocationsPipelinelocalf0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsPipelinelocalf = locationsPipelinelocalf1 + + locationsPipelinelocalf1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsPipelinelocalf(ctx context.Context, exec bob.Executor, locationsPipelinelocalf1 *LocationsPipelinelocalf) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsPipelinelocalf0(ctx, exec, 1, locationsPipelinelocalf1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsPipelinelocalf = locationsPipelinelocalf1 + + locationsPipelinelocalf1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsRclone0(ctx context.Context, exec bob.Executor, locationsRclone1 *LocationsRcloneSetter, locationsSpace0 *LocationsSpace) (*LocationsRclone, error) { + locationsRclone1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsRclones.Insert(locationsRclone1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsRclone0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsRclone0(ctx context.Context, exec bob.Executor, count int, locationsRclone1 *LocationsRclone, locationsSpace0 *LocationsSpace) (*LocationsRclone, error) { + setter := &LocationsRcloneSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsRclone1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsRclone0: %w", err) + } + + return locationsRclone1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsRclone(ctx context.Context, exec bob.Executor, related *LocationsRcloneSetter) error { + var err error + + locationsRclone1, err := insertLocationsSpaceSpaceLocationsRclone0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsRclone = locationsRclone1 + + locationsRclone1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsRclone(ctx context.Context, exec bob.Executor, locationsRclone1 *LocationsRclone) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsRclone0(ctx, exec, 1, locationsRclone1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsRclone = locationsRclone1 + + locationsRclone1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsS30(ctx context.Context, exec bob.Executor, locationsS31 *LocationsS3Setter, locationsSpace0 *LocationsSpace) (*LocationsS3, error) { + locationsS31.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsS3S.Insert(locationsS31).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsS30: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsS30(ctx context.Context, exec bob.Executor, count int, locationsS31 *LocationsS3, locationsSpace0 *LocationsSpace) (*LocationsS3, error) { + setter := &LocationsS3Setter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsS31.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsS30: %w", err) + } + + return locationsS31, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsS3(ctx context.Context, exec bob.Executor, related *LocationsS3Setter) error { + var err error + + locationsS31, err := insertLocationsSpaceSpaceLocationsS30(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsS3 = locationsS31 + + locationsS31.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsS3(ctx context.Context, exec bob.Executor, locationsS31 *LocationsS3) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsS30(ctx, exec, 1, locationsS31, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsS3 = locationsS31 + + locationsS31.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func insertLocationsSpaceSpaceLocationsSwift0(ctx context.Context, exec bob.Executor, locationsSwift1 *LocationsSwiftSetter, locationsSpace0 *LocationsSpace) (*LocationsSwift, error) { + locationsSwift1.SpaceID = omit.From(locationsSpace0.UUID) + + ret, err := LocationsSwifts.Insert(locationsSwift1).One(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertLocationsSpaceSpaceLocationsSwift0: %w", err) + } + + return ret, nil +} + +func attachLocationsSpaceSpaceLocationsSwift0(ctx context.Context, exec bob.Executor, count int, locationsSwift1 *LocationsSwift, locationsSpace0 *LocationsSpace) (*LocationsSwift, error) { + setter := &LocationsSwiftSetter{ + SpaceID: omit.From(locationsSpace0.UUID), + } + + err := locationsSwift1.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSpaceSpaceLocationsSwift0: %w", err) + } + + return locationsSwift1, nil +} + +func (locationsSpace0 *LocationsSpace) InsertSpaceLocationsSwift(ctx context.Context, exec bob.Executor, related *LocationsSwiftSetter) error { + var err error + + locationsSwift1, err := insertLocationsSpaceSpaceLocationsSwift0(ctx, exec, related, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsSwift = locationsSwift1 + + locationsSwift1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +func (locationsSpace0 *LocationsSpace) AttachSpaceLocationsSwift(ctx context.Context, exec bob.Executor, locationsSwift1 *LocationsSwift) error { + var err error + + _, err = attachLocationsSpaceSpaceLocationsSwift0(ctx, exec, 1, locationsSwift1, locationsSpace0) + if err != nil { + return err + } + + locationsSpace0.R.SpaceLocationsSwift = locationsSwift1 + + locationsSwift1.R.SpaceLocationsSpace = locationsSpace0 + + return nil +} + +type locationsSpaceWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + UUID mysql.WhereMod[Q, string] + AccessProtocol mysql.WhereMod[Q, string] + Size mysql.WhereNullMod[Q, int64] + Used mysql.WhereMod[Q, int64] + Path mysql.WhereMod[Q, string] + Verified mysql.WhereMod[Q, bool] + LastVerified mysql.WhereNullMod[Q, time.Time] + StagingPath mysql.WhereMod[Q, string] +} + +func (locationsSpaceWhere[Q]) AliasedAs(alias string) locationsSpaceWhere[Q] { + return buildLocationsSpaceWhere[Q](buildLocationsSpaceColumns(alias)) +} + +func buildLocationsSpaceWhere[Q mysql.Filterable](cols locationsSpaceColumns) locationsSpaceWhere[Q] { + return locationsSpaceWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + UUID: mysql.Where[Q, string](cols.UUID), + AccessProtocol: mysql.Where[Q, string](cols.AccessProtocol), + Size: mysql.WhereNull[Q, int64](cols.Size), + Used: mysql.Where[Q, int64](cols.Used), + Path: mysql.Where[Q, string](cols.Path), + Verified: mysql.Where[Q, bool](cols.Verified), + LastVerified: mysql.WhereNull[Q, time.Time](cols.LastVerified), + StagingPath: mysql.Where[Q, string](cols.StagingPath), + } +} + +func (o *LocationsSpace) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsArchipelago": + rel, ok := retrieved.(*LocationsArchipelago) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsArchipelago = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsArkivum": + rel, ok := retrieved.(*LocationsArkivum) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsArkivum = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsDataverse": + rel, ok := retrieved.(*LocationsDataverse) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsDataverse = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsDspace": + rel, ok := retrieved.(*LocationsDspace) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsDspace = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsDspacerest": + rel, ok := retrieved.(*LocationsDspacerest) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsDspacerest = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsDuracloud": + rel, ok := retrieved.(*LocationsDuracloud) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsDuracloud = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsFedora": + rel, ok := retrieved.(*LocationsFedora) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsFedora = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsGPG": + rel, ok := retrieved.(*LocationsGPG) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsGPG = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsLocalfilesystem": + rel, ok := retrieved.(*LocationsLocalfilesystem) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsLocalfilesystem = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsLocations": + rels, ok := retrieved.(LocationsLocationSlice) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsLocations = rels + + for _, rel := range rels { + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + } + return nil + case "SpaceLocationsLockssomatic": + rel, ok := retrieved.(*LocationsLockssomatic) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsLockssomatic = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsNF": + rel, ok := retrieved.(*LocationsNF) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsNF = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsOfflinereplicastaging": + rel, ok := retrieved.(*LocationsOfflinereplicastaging) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsOfflinereplicastaging = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsPipelinelocalf": + rel, ok := retrieved.(*LocationsPipelinelocalf) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsPipelinelocalf = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsRclone": + rel, ok := retrieved.(*LocationsRclone) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsRclone = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsS3": + rel, ok := retrieved.(*LocationsS3) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsS3 = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + case "SpaceLocationsSwift": + rel, ok := retrieved.(*LocationsSwift) + if !ok { + return fmt.Errorf("locationsSpace cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSwift = rel + + if rel != nil { + rel.R.SpaceLocationsSpace = o + } + return nil + default: + return fmt.Errorf("locationsSpace has no relationship %q", name) + } +} + +type locationsSpacePreloader struct { + SpaceLocationsArchipelago func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsArkivum func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsDataverse func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsDspace func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsDspacerest func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsDuracloud func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsFedora func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsGPG func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsLocalfilesystem func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsLockssomatic func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsNF func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsOfflinereplicastaging func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsPipelinelocalf func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsRclone func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsS3 func(...mysql.PreloadOption) mysql.Preloader + SpaceLocationsSwift func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsSpacePreloader() locationsSpacePreloader { + return locationsSpacePreloader{ + SpaceLocationsArchipelago: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsArchipelago, LocationsArchipelagoSlice](mysql.PreloadRel{ + Name: "SpaceLocationsArchipelago", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsArchipelagos, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsArchipelagos.Columns.Names(), opts...) + }, + SpaceLocationsArkivum: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsArkivum, LocationsArkivumSlice](mysql.PreloadRel{ + Name: "SpaceLocationsArkivum", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsArkivums, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsArkivums.Columns.Names(), opts...) + }, + SpaceLocationsDataverse: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsDataverse, LocationsDataverseSlice](mysql.PreloadRel{ + Name: "SpaceLocationsDataverse", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsDataverses, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsDataverses.Columns.Names(), opts...) + }, + SpaceLocationsDspace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsDspace, LocationsDspaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsDspace", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsDspaces, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsDspaces.Columns.Names(), opts...) + }, + SpaceLocationsDspacerest: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsDspacerest, LocationsDspacerestSlice](mysql.PreloadRel{ + Name: "SpaceLocationsDspacerest", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsDspacerests, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsDspacerests.Columns.Names(), opts...) + }, + SpaceLocationsDuracloud: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsDuracloud, LocationsDuracloudSlice](mysql.PreloadRel{ + Name: "SpaceLocationsDuracloud", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsDuraclouds, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsDuraclouds.Columns.Names(), opts...) + }, + SpaceLocationsFedora: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsFedora, LocationsFedoraSlice](mysql.PreloadRel{ + Name: "SpaceLocationsFedora", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsFedoras, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsFedoras.Columns.Names(), opts...) + }, + SpaceLocationsGPG: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsGPG, LocationsGPGSlice](mysql.PreloadRel{ + Name: "SpaceLocationsGPG", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsGPGS, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsGPGS.Columns.Names(), opts...) + }, + SpaceLocationsLocalfilesystem: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsLocalfilesystem, LocationsLocalfilesystemSlice](mysql.PreloadRel{ + Name: "SpaceLocationsLocalfilesystem", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsLocalfilesystems, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsLocalfilesystems.Columns.Names(), opts...) + }, + SpaceLocationsLockssomatic: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsLockssomatic, LocationsLockssomaticSlice](mysql.PreloadRel{ + Name: "SpaceLocationsLockssomatic", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsLockssomatics, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsLockssomatics.Columns.Names(), opts...) + }, + SpaceLocationsNF: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsNF, LocationsNFSlice](mysql.PreloadRel{ + Name: "SpaceLocationsNF", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsNFS, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsNFS.Columns.Names(), opts...) + }, + SpaceLocationsOfflinereplicastaging: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsOfflinereplicastaging, LocationsOfflinereplicastagingSlice](mysql.PreloadRel{ + Name: "SpaceLocationsOfflinereplicastaging", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsOfflinereplicastagings, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsOfflinereplicastagings.Columns.Names(), opts...) + }, + SpaceLocationsPipelinelocalf: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsPipelinelocalf, LocationsPipelinelocalfSlice](mysql.PreloadRel{ + Name: "SpaceLocationsPipelinelocalf", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsPipelinelocalfs, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsPipelinelocalfs.Columns.Names(), opts...) + }, + SpaceLocationsRclone: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsRclone, LocationsRcloneSlice](mysql.PreloadRel{ + Name: "SpaceLocationsRclone", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsRclones, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsRclones.Columns.Names(), opts...) + }, + SpaceLocationsS3: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsS3, LocationsS3Slice](mysql.PreloadRel{ + Name: "SpaceLocationsS3", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsS3S, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsS3S.Columns.Names(), opts...) + }, + SpaceLocationsSwift: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSwift, LocationsSwiftSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSwift", + Sides: []mysql.PreloadSide{ + { + From: LocationsSpaces, + To: LocationsSwifts, + FromColumns: []string{"uuid"}, + ToColumns: []string{"space_id"}, + }, + }, + }, LocationsSwifts.Columns.Names(), opts...) + }, + } +} + +type locationsSpaceThenLoader[Q orm.Loadable] struct { + SpaceLocationsArchipelago func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsArkivum func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsDataverse func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsDspace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsDspacerest func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsDuracloud func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsFedora func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsGPG func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsLocalfilesystem func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsLocations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsLockssomatic func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsNF func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsOfflinereplicastaging func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsPipelinelocalf func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsRclone func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsS3 func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + SpaceLocationsSwift func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsSpaceThenLoader[Q orm.Loadable]() locationsSpaceThenLoader[Q] { + type SpaceLocationsArchipelagoLoadInterface interface { + LoadSpaceLocationsArchipelago(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsArkivumLoadInterface interface { + LoadSpaceLocationsArkivum(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsDataverseLoadInterface interface { + LoadSpaceLocationsDataverse(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsDspaceLoadInterface interface { + LoadSpaceLocationsDspace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsDspacerestLoadInterface interface { + LoadSpaceLocationsDspacerest(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsDuracloudLoadInterface interface { + LoadSpaceLocationsDuracloud(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsFedoraLoadInterface interface { + LoadSpaceLocationsFedora(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsGPGLoadInterface interface { + LoadSpaceLocationsGPG(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsLocalfilesystemLoadInterface interface { + LoadSpaceLocationsLocalfilesystem(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsLocationsLoadInterface interface { + LoadSpaceLocationsLocations(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsLockssomaticLoadInterface interface { + LoadSpaceLocationsLockssomatic(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsNFLoadInterface interface { + LoadSpaceLocationsNF(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsOfflinereplicastagingLoadInterface interface { + LoadSpaceLocationsOfflinereplicastaging(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsPipelinelocalfLoadInterface interface { + LoadSpaceLocationsPipelinelocalf(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsRcloneLoadInterface interface { + LoadSpaceLocationsRclone(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsS3LoadInterface interface { + LoadSpaceLocationsS3(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type SpaceLocationsSwiftLoadInterface interface { + LoadSpaceLocationsSwift(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsSpaceThenLoader[Q]{ + SpaceLocationsArchipelago: thenLoadBuilder[Q]( + "SpaceLocationsArchipelago", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsArchipelagoLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsArchipelago(ctx, exec, mods...) + }, + ), + SpaceLocationsArkivum: thenLoadBuilder[Q]( + "SpaceLocationsArkivum", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsArkivumLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsArkivum(ctx, exec, mods...) + }, + ), + SpaceLocationsDataverse: thenLoadBuilder[Q]( + "SpaceLocationsDataverse", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsDataverseLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsDataverse(ctx, exec, mods...) + }, + ), + SpaceLocationsDspace: thenLoadBuilder[Q]( + "SpaceLocationsDspace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsDspaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsDspace(ctx, exec, mods...) + }, + ), + SpaceLocationsDspacerest: thenLoadBuilder[Q]( + "SpaceLocationsDspacerest", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsDspacerestLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsDspacerest(ctx, exec, mods...) + }, + ), + SpaceLocationsDuracloud: thenLoadBuilder[Q]( + "SpaceLocationsDuracloud", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsDuracloudLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsDuracloud(ctx, exec, mods...) + }, + ), + SpaceLocationsFedora: thenLoadBuilder[Q]( + "SpaceLocationsFedora", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsFedoraLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsFedora(ctx, exec, mods...) + }, + ), + SpaceLocationsGPG: thenLoadBuilder[Q]( + "SpaceLocationsGPG", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsGPGLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsGPG(ctx, exec, mods...) + }, + ), + SpaceLocationsLocalfilesystem: thenLoadBuilder[Q]( + "SpaceLocationsLocalfilesystem", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsLocalfilesystemLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsLocalfilesystem(ctx, exec, mods...) + }, + ), + SpaceLocationsLocations: thenLoadBuilder[Q]( + "SpaceLocationsLocations", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsLocationsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsLocations(ctx, exec, mods...) + }, + ), + SpaceLocationsLockssomatic: thenLoadBuilder[Q]( + "SpaceLocationsLockssomatic", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsLockssomaticLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsLockssomatic(ctx, exec, mods...) + }, + ), + SpaceLocationsNF: thenLoadBuilder[Q]( + "SpaceLocationsNF", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsNFLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsNF(ctx, exec, mods...) + }, + ), + SpaceLocationsOfflinereplicastaging: thenLoadBuilder[Q]( + "SpaceLocationsOfflinereplicastaging", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsOfflinereplicastagingLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsOfflinereplicastaging(ctx, exec, mods...) + }, + ), + SpaceLocationsPipelinelocalf: thenLoadBuilder[Q]( + "SpaceLocationsPipelinelocalf", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsPipelinelocalfLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsPipelinelocalf(ctx, exec, mods...) + }, + ), + SpaceLocationsRclone: thenLoadBuilder[Q]( + "SpaceLocationsRclone", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsRcloneLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsRclone(ctx, exec, mods...) + }, + ), + SpaceLocationsS3: thenLoadBuilder[Q]( + "SpaceLocationsS3", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsS3LoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsS3(ctx, exec, mods...) + }, + ), + SpaceLocationsSwift: thenLoadBuilder[Q]( + "SpaceLocationsSwift", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSwiftLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSwift(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsArchipelago loads the locationsSpace's SpaceLocationsArchipelago into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsArchipelago(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsArchipelago = nil + + related, err := o.SpaceLocationsArchipelago(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsArchipelago = related + return nil +} + +// LoadSpaceLocationsArchipelago loads the locationsSpace's SpaceLocationsArchipelago into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsArchipelago(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsArchipelagos, err := os.SpaceLocationsArchipelago(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsArchipelagos { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsArchipelago = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsArkivum loads the locationsSpace's SpaceLocationsArkivum into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsArkivum(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsArkivum = nil + + related, err := o.SpaceLocationsArkivum(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsArkivum = related + return nil +} + +// LoadSpaceLocationsArkivum loads the locationsSpace's SpaceLocationsArkivum into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsArkivum(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsArkivums, err := os.SpaceLocationsArkivum(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsArkivums { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsArkivum = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsDataverse loads the locationsSpace's SpaceLocationsDataverse into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsDataverse(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsDataverse = nil + + related, err := o.SpaceLocationsDataverse(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsDataverse = related + return nil +} + +// LoadSpaceLocationsDataverse loads the locationsSpace's SpaceLocationsDataverse into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsDataverse(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsDataverses, err := os.SpaceLocationsDataverse(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsDataverses { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsDataverse = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsDspace loads the locationsSpace's SpaceLocationsDspace into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsDspace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsDspace = nil + + related, err := o.SpaceLocationsDspace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsDspace = related + return nil +} + +// LoadSpaceLocationsDspace loads the locationsSpace's SpaceLocationsDspace into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsDspace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsDspaces, err := os.SpaceLocationsDspace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsDspaces { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsDspace = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsDspacerest loads the locationsSpace's SpaceLocationsDspacerest into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsDspacerest(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsDspacerest = nil + + related, err := o.SpaceLocationsDspacerest(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsDspacerest = related + return nil +} + +// LoadSpaceLocationsDspacerest loads the locationsSpace's SpaceLocationsDspacerest into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsDspacerest(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsDspacerests, err := os.SpaceLocationsDspacerest(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsDspacerests { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsDspacerest = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsDuracloud loads the locationsSpace's SpaceLocationsDuracloud into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsDuracloud(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsDuracloud = nil + + related, err := o.SpaceLocationsDuracloud(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsDuracloud = related + return nil +} + +// LoadSpaceLocationsDuracloud loads the locationsSpace's SpaceLocationsDuracloud into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsDuracloud(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsDuraclouds, err := os.SpaceLocationsDuracloud(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsDuraclouds { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsDuracloud = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsFedora loads the locationsSpace's SpaceLocationsFedora into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsFedora(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsFedora = nil + + related, err := o.SpaceLocationsFedora(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsFedora = related + return nil +} + +// LoadSpaceLocationsFedora loads the locationsSpace's SpaceLocationsFedora into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsFedora(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsFedoras, err := os.SpaceLocationsFedora(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsFedoras { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsFedora = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsGPG loads the locationsSpace's SpaceLocationsGPG into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsGPG(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsGPG = nil + + related, err := o.SpaceLocationsGPG(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsGPG = related + return nil +} + +// LoadSpaceLocationsGPG loads the locationsSpace's SpaceLocationsGPG into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsGPG(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsGPGS, err := os.SpaceLocationsGPG(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsGPGS { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsGPG = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsLocalfilesystem loads the locationsSpace's SpaceLocationsLocalfilesystem into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsLocalfilesystem(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsLocalfilesystem = nil + + related, err := o.SpaceLocationsLocalfilesystem(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsLocalfilesystem = related + return nil +} + +// LoadSpaceLocationsLocalfilesystem loads the locationsSpace's SpaceLocationsLocalfilesystem into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsLocalfilesystem(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocalfilesystems, err := os.SpaceLocationsLocalfilesystem(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocalfilesystems { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsLocalfilesystem = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsLocations loads the locationsSpace's SpaceLocationsLocations into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsLocations(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsLocations = nil + + related, err := o.SpaceLocationsLocations(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.SpaceLocationsSpace = o + } + + o.R.SpaceLocationsLocations = related + return nil +} + +// LoadSpaceLocationsLocations loads the locationsSpace's SpaceLocationsLocations into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsLocations(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLocations, err := os.SpaceLocationsLocations(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.SpaceLocationsLocations = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLocations { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsLocations = append(o.R.SpaceLocationsLocations, rel) + } + } + + return nil +} + +// LoadSpaceLocationsLockssomatic loads the locationsSpace's SpaceLocationsLockssomatic into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsLockssomatic(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsLockssomatic = nil + + related, err := o.SpaceLocationsLockssomatic(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsLockssomatic = related + return nil +} + +// LoadSpaceLocationsLockssomatic loads the locationsSpace's SpaceLocationsLockssomatic into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsLockssomatic(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsLockssomatics, err := os.SpaceLocationsLockssomatic(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsLockssomatics { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsLockssomatic = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsNF loads the locationsSpace's SpaceLocationsNF into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsNF(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsNF = nil + + related, err := o.SpaceLocationsNF(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsNF = related + return nil +} + +// LoadSpaceLocationsNF loads the locationsSpace's SpaceLocationsNF into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsNF(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsNFS, err := os.SpaceLocationsNF(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsNFS { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsNF = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsOfflinereplicastaging loads the locationsSpace's SpaceLocationsOfflinereplicastaging into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsOfflinereplicastaging(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsOfflinereplicastaging = nil + + related, err := o.SpaceLocationsOfflinereplicastaging(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsOfflinereplicastaging = related + return nil +} + +// LoadSpaceLocationsOfflinereplicastaging loads the locationsSpace's SpaceLocationsOfflinereplicastaging into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsOfflinereplicastaging(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsOfflinereplicastagings, err := os.SpaceLocationsOfflinereplicastaging(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsOfflinereplicastagings { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsOfflinereplicastaging = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsPipelinelocalf loads the locationsSpace's SpaceLocationsPipelinelocalf into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsPipelinelocalf(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsPipelinelocalf = nil + + related, err := o.SpaceLocationsPipelinelocalf(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsPipelinelocalf = related + return nil +} + +// LoadSpaceLocationsPipelinelocalf loads the locationsSpace's SpaceLocationsPipelinelocalf into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsPipelinelocalf(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsPipelinelocalfs, err := os.SpaceLocationsPipelinelocalf(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsPipelinelocalfs { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsPipelinelocalf = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsRclone loads the locationsSpace's SpaceLocationsRclone into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsRclone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsRclone = nil + + related, err := o.SpaceLocationsRclone(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsRclone = related + return nil +} + +// LoadSpaceLocationsRclone loads the locationsSpace's SpaceLocationsRclone into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsRclone(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsRclones, err := os.SpaceLocationsRclone(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsRclones { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsRclone = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsS3 loads the locationsSpace's SpaceLocationsS3 into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsS3(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsS3 = nil + + related, err := o.SpaceLocationsS3(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsS3 = related + return nil +} + +// LoadSpaceLocationsS3 loads the locationsSpace's SpaceLocationsS3 into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsS3(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsS3S, err := os.SpaceLocationsS3(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsS3S { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsS3 = rel + break + } + } + + return nil +} + +// LoadSpaceLocationsSwift loads the locationsSpace's SpaceLocationsSwift into the .R struct +func (o *LocationsSpace) LoadSpaceLocationsSwift(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSwift = nil + + related, err := o.SpaceLocationsSwift(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsSwift = related + return nil +} + +// LoadSpaceLocationsSwift loads the locationsSpace's SpaceLocationsSwift into the .R struct +func (os LocationsSpaceSlice) LoadSpaceLocationsSwift(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSwifts, err := os.SpaceLocationsSwift(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSwifts { + + if !(o.UUID == rel.SpaceID) { + continue + } + + rel.R.SpaceLocationsSpace = o + + o.R.SpaceLocationsSwift = rel + break + } + } + + return nil +} + +type locationsSpaceJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsArchipelago modAs[Q, locationsArchipelagoColumns] + SpaceLocationsArkivum modAs[Q, locationsArkivumColumns] + SpaceLocationsDataverse modAs[Q, locationsDataverseColumns] + SpaceLocationsDspace modAs[Q, locationsDspaceColumns] + SpaceLocationsDspacerest modAs[Q, locationsDspacerestColumns] + SpaceLocationsDuracloud modAs[Q, locationsDuracloudColumns] + SpaceLocationsFedora modAs[Q, locationsFedoraColumns] + SpaceLocationsGPG modAs[Q, locationsGPGColumns] + SpaceLocationsLocalfilesystem modAs[Q, locationsLocalfilesystemColumns] + SpaceLocationsLocations modAs[Q, locationsLocationColumns] + SpaceLocationsLockssomatic modAs[Q, locationsLockssomaticColumns] + SpaceLocationsNF modAs[Q, locationsNFColumns] + SpaceLocationsOfflinereplicastaging modAs[Q, locationsOfflinereplicastagingColumns] + SpaceLocationsPipelinelocalf modAs[Q, locationsPipelinelocalfColumns] + SpaceLocationsRclone modAs[Q, locationsRcloneColumns] + SpaceLocationsS3 modAs[Q, locationsS3Columns] + SpaceLocationsSwift modAs[Q, locationsSwiftColumns] +} + +func (j locationsSpaceJoins[Q]) aliasedAs(alias string) locationsSpaceJoins[Q] { + return buildLocationsSpaceJoins[Q](buildLocationsSpaceColumns(alias), j.typ) +} + +func buildLocationsSpaceJoins[Q dialect.Joinable](cols locationsSpaceColumns, typ string) locationsSpaceJoins[Q] { + return locationsSpaceJoins[Q]{ + typ: typ, + SpaceLocationsArchipelago: modAs[Q, locationsArchipelagoColumns]{ + c: LocationsArchipelagos.Columns, + f: func(to locationsArchipelagoColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsArchipelagos.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsArkivum: modAs[Q, locationsArkivumColumns]{ + c: LocationsArkivums.Columns, + f: func(to locationsArkivumColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsArkivums.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsDataverse: modAs[Q, locationsDataverseColumns]{ + c: LocationsDataverses.Columns, + f: func(to locationsDataverseColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsDataverses.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsDspace: modAs[Q, locationsDspaceColumns]{ + c: LocationsDspaces.Columns, + f: func(to locationsDspaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsDspaces.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsDspacerest: modAs[Q, locationsDspacerestColumns]{ + c: LocationsDspacerests.Columns, + f: func(to locationsDspacerestColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsDspacerests.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsDuracloud: modAs[Q, locationsDuracloudColumns]{ + c: LocationsDuraclouds.Columns, + f: func(to locationsDuracloudColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsDuraclouds.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsFedora: modAs[Q, locationsFedoraColumns]{ + c: LocationsFedoras.Columns, + f: func(to locationsFedoraColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsFedoras.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsGPG: modAs[Q, locationsGPGColumns]{ + c: LocationsGPGS.Columns, + f: func(to locationsGPGColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsGPGS.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsLocalfilesystem: modAs[Q, locationsLocalfilesystemColumns]{ + c: LocationsLocalfilesystems.Columns, + f: func(to locationsLocalfilesystemColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocalfilesystems.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsLocations: modAs[Q, locationsLocationColumns]{ + c: LocationsLocations.Columns, + f: func(to locationsLocationColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLocations.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsLockssomatic: modAs[Q, locationsLockssomaticColumns]{ + c: LocationsLockssomatics.Columns, + f: func(to locationsLockssomaticColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsLockssomatics.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsNF: modAs[Q, locationsNFColumns]{ + c: LocationsNFS.Columns, + f: func(to locationsNFColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsNFS.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsOfflinereplicastaging: modAs[Q, locationsOfflinereplicastagingColumns]{ + c: LocationsOfflinereplicastagings.Columns, + f: func(to locationsOfflinereplicastagingColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsOfflinereplicastagings.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsPipelinelocalf: modAs[Q, locationsPipelinelocalfColumns]{ + c: LocationsPipelinelocalfs.Columns, + f: func(to locationsPipelinelocalfColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsPipelinelocalfs.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsRclone: modAs[Q, locationsRcloneColumns]{ + c: LocationsRclones.Columns, + f: func(to locationsRcloneColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsRclones.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsS3: modAs[Q, locationsS3Columns]{ + c: LocationsS3S.Columns, + f: func(to locationsS3Columns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsS3S.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + SpaceLocationsSwift: modAs[Q, locationsSwiftColumns]{ + c: LocationsSwifts.Columns, + f: func(to locationsSwiftColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSwifts.Name().As(to.Alias())).On( + to.SpaceID.EQ(cols.UUID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/locations_swift.bob.go b/database/storage_service/models/locations_swift.bob.go new file mode 100644 index 0000000..0327196 --- /dev/null +++ b/database/storage_service/models/locations_swift.bob.go @@ -0,0 +1,762 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// LocationsSwift is an object representing the database table. +type LocationsSwift struct { + ID int32 `db:"id,pk,autoincr" ` + AuthURL string `db:"auth_url" ` + AuthVersion string `db:"auth_version" ` + Username string `db:"username" ` + Password string `db:"password" ` + Container string `db:"container" ` + Tenant null.Val[string] `db:"tenant" ` + Region null.Val[string] `db:"region" ` + SpaceID string `db:"space_id" ` + + R locationsSwiftR `db:"-" ` +} + +// LocationsSwiftSlice is an alias for a slice of pointers to LocationsSwift. +// This should almost always be used instead of []*LocationsSwift. +type LocationsSwiftSlice []*LocationsSwift + +// LocationsSwifts contains methods to work with the locations_swift table +var LocationsSwifts = mysql.NewTablex[*LocationsSwift, LocationsSwiftSlice, *LocationsSwiftSetter]("locations_swift", buildLocationsSwiftColumns("locations_swift"), []string{"id"}, []string{"space_id"}) + +// LocationsSwiftsQuery is a query on the locations_swift table +type LocationsSwiftsQuery = *mysql.ViewQuery[*LocationsSwift, LocationsSwiftSlice] + +// locationsSwiftR is where relationships are stored. +type locationsSwiftR struct { + SpaceLocationsSpace *LocationsSpace // locations_swift_space_id_9cfded49_fk_locations_space_uuid +} + +func buildLocationsSwiftColumns(alias string) locationsSwiftColumns { + return locationsSwiftColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "auth_url", "auth_version", "username", "password", "container", "tenant", "region", "space_id", + ).WithParent("locations_swift"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + AuthURL: mysql.Quote(alias, "auth_url"), + AuthVersion: mysql.Quote(alias, "auth_version"), + Username: mysql.Quote(alias, "username"), + Password: mysql.Quote(alias, "password"), + Container: mysql.Quote(alias, "container"), + Tenant: mysql.Quote(alias, "tenant"), + Region: mysql.Quote(alias, "region"), + SpaceID: mysql.Quote(alias, "space_id"), + } +} + +type locationsSwiftColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + AuthURL mysql.Expression + AuthVersion mysql.Expression + Username mysql.Expression + Password mysql.Expression + Container mysql.Expression + Tenant mysql.Expression + Region mysql.Expression + SpaceID mysql.Expression +} + +func (c locationsSwiftColumns) Alias() string { + return c.tableAlias +} + +func (locationsSwiftColumns) AliasedAs(alias string) locationsSwiftColumns { + return buildLocationsSwiftColumns(alias) +} + +// LocationsSwiftSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type LocationsSwiftSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + AuthURL omit.Val[string] `db:"auth_url" ` + AuthVersion omit.Val[string] `db:"auth_version" ` + Username omit.Val[string] `db:"username" ` + Password omit.Val[string] `db:"password" ` + Container omit.Val[string] `db:"container" ` + Tenant omitnull.Val[string] `db:"tenant" ` + Region omitnull.Val[string] `db:"region" ` + SpaceID omit.Val[string] `db:"space_id" ` +} + +func (s LocationsSwiftSetter) SetColumns() []string { + vals := make([]string, 0, 9) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.AuthURL.IsValue() { + vals = append(vals, "auth_url") + } + if s.AuthVersion.IsValue() { + vals = append(vals, "auth_version") + } + if s.Username.IsValue() { + vals = append(vals, "username") + } + if s.Password.IsValue() { + vals = append(vals, "password") + } + if s.Container.IsValue() { + vals = append(vals, "container") + } + if !s.Tenant.IsUnset() { + vals = append(vals, "tenant") + } + if !s.Region.IsUnset() { + vals = append(vals, "region") + } + if s.SpaceID.IsValue() { + vals = append(vals, "space_id") + } + return vals +} + +func (s LocationsSwiftSetter) Overwrite(t *LocationsSwift) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.AuthURL.IsValue() { + t.AuthURL = s.AuthURL.MustGet() + } + if s.AuthVersion.IsValue() { + t.AuthVersion = s.AuthVersion.MustGet() + } + if s.Username.IsValue() { + t.Username = s.Username.MustGet() + } + if s.Password.IsValue() { + t.Password = s.Password.MustGet() + } + if s.Container.IsValue() { + t.Container = s.Container.MustGet() + } + if !s.Tenant.IsUnset() { + t.Tenant = s.Tenant.MustGetNull() + } + if !s.Region.IsUnset() { + t.Region = s.Region.MustGetNull() + } + if s.SpaceID.IsValue() { + t.SpaceID = s.SpaceID.MustGet() + } +} + +func (s *LocationsSwiftSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsSwifts.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AuthURL.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AuthURL.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.AuthVersion.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.AuthVersion.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Username.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Username.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Password.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Password.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Container.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Container.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Tenant.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Tenant.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(!s.Region.IsUnset()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Region.MustGetNull()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.SpaceID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.SpaceID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s LocationsSwiftSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("locations_swift")...) +} + +func (s LocationsSwiftSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 9) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.AuthURL.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "auth_url")...), + mysql.Arg(s.AuthURL), + }}) + } + + if s.AuthVersion.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "auth_version")...), + mysql.Arg(s.AuthVersion), + }}) + } + + if s.Username.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "username")...), + mysql.Arg(s.Username), + }}) + } + + if s.Password.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "password")...), + mysql.Arg(s.Password), + }}) + } + + if s.Container.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "container")...), + mysql.Arg(s.Container), + }}) + } + + if !s.Tenant.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "tenant")...), + mysql.Arg(s.Tenant), + }}) + } + + if !s.Region.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "region")...), + mysql.Arg(s.Region), + }}) + } + + if s.SpaceID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "space_id")...), + mysql.Arg(s.SpaceID), + }}) + } + + return exprs +} + +// FindLocationsSwift retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindLocationsSwift(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*LocationsSwift, error) { + if len(cols) == 0 { + return LocationsSwifts.Query( + sm.Where(LocationsSwifts.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return LocationsSwifts.Query( + sm.Where(LocationsSwifts.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(LocationsSwifts.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// LocationsSwiftExists checks the presence of a single record by primary key +func LocationsSwiftExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return LocationsSwifts.Query( + sm.Where(LocationsSwifts.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after LocationsSwift is retrieved from the database +func (o *LocationsSwift) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsSwifts.AfterSelectHooks.RunHooks(ctx, exec, LocationsSwiftSlice{o}) + case bob.QueryTypeInsert: + ctx, err = LocationsSwifts.AfterInsertHooks.RunHooks(ctx, exec, LocationsSwiftSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = LocationsSwifts.AfterUpdateHooks.RunHooks(ctx, exec, LocationsSwiftSlice{o}) + case bob.QueryTypeDelete: + ctx, err = LocationsSwifts.AfterDeleteHooks.RunHooks(ctx, exec, LocationsSwiftSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the LocationsSwift +func (o *LocationsSwift) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *LocationsSwift) pkEQ() dialect.Expression { + return mysql.Quote("locations_swift", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the LocationsSwift +func (o *LocationsSwift) Update(ctx context.Context, exec bob.Executor, s *LocationsSwiftSetter) error { + _, err := LocationsSwifts.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single LocationsSwift record with an executor +func (o *LocationsSwift) Delete(ctx context.Context, exec bob.Executor) error { + _, err := LocationsSwifts.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the LocationsSwift using the executor +func (o *LocationsSwift) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := LocationsSwifts.Query( + sm.Where(LocationsSwifts.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after LocationsSwiftSlice is retrieved from the database +func (o LocationsSwiftSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = LocationsSwifts.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = LocationsSwifts.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = LocationsSwifts.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = LocationsSwifts.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o LocationsSwiftSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("locations_swift", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o LocationsSwiftSlice) copyMatchingRows(from ...*LocationsSwift) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o LocationsSwiftSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsSwifts.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsSwift: + o.copyMatchingRows(retrieved) + case []*LocationsSwift: + o.copyMatchingRows(retrieved...) + case LocationsSwiftSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsSwift or a slice of LocationsSwift + // then run the AfterUpdateHooks on the slice + _, err = LocationsSwifts.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o LocationsSwiftSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return LocationsSwifts.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *LocationsSwift: + o.copyMatchingRows(retrieved) + case []*LocationsSwift: + o.copyMatchingRows(retrieved...) + case LocationsSwiftSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a LocationsSwift or a slice of LocationsSwift + // then run the AfterDeleteHooks on the slice + _, err = LocationsSwifts.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o LocationsSwiftSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals LocationsSwiftSetter) error { + _, err := LocationsSwifts.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o LocationsSwiftSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := LocationsSwifts.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o LocationsSwiftSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := LocationsSwifts.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// SpaceLocationsSpace starts a query for related objects on locations_space +func (o *LocationsSwift) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + return LocationsSpaces.Query(append(mods, + sm.Where(LocationsSpaces.Columns.UUID.EQ(mysql.Arg(o.SpaceID))), + )...) +} + +func (os LocationsSwiftSlice) SpaceLocationsSpace(mods ...bob.Mod[*dialect.SelectQuery]) LocationsSpacesQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.SpaceID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return LocationsSpaces.Query(append(mods, + sm.Where(mysql.Group(LocationsSpaces.Columns.UUID).OP("IN", PKArgExpr)), + )...) +} + +func attachLocationsSwiftSpaceLocationsSpace0(ctx context.Context, exec bob.Executor, count int, locationsSwift0 *LocationsSwift, locationsSpace1 *LocationsSpace) (*LocationsSwift, error) { + setter := &LocationsSwiftSetter{ + SpaceID: omit.From(locationsSpace1.UUID), + } + + err := locationsSwift0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachLocationsSwiftSpaceLocationsSpace0: %w", err) + } + + return locationsSwift0, nil +} + +func (locationsSwift0 *LocationsSwift) InsertSpaceLocationsSpace(ctx context.Context, exec bob.Executor, related *LocationsSpaceSetter) error { + var err error + + locationsSpace1, err := LocationsSpaces.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachLocationsSwiftSpaceLocationsSpace0(ctx, exec, 1, locationsSwift0, locationsSpace1) + if err != nil { + return err + } + + locationsSwift0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsSwift = locationsSwift0 + + return nil +} + +func (locationsSwift0 *LocationsSwift) AttachSpaceLocationsSpace(ctx context.Context, exec bob.Executor, locationsSpace1 *LocationsSpace) error { + var err error + + _, err = attachLocationsSwiftSpaceLocationsSpace0(ctx, exec, 1, locationsSwift0, locationsSpace1) + if err != nil { + return err + } + + locationsSwift0.R.SpaceLocationsSpace = locationsSpace1 + + locationsSpace1.R.SpaceLocationsSwift = locationsSwift0 + + return nil +} + +type locationsSwiftWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + AuthURL mysql.WhereMod[Q, string] + AuthVersion mysql.WhereMod[Q, string] + Username mysql.WhereMod[Q, string] + Password mysql.WhereMod[Q, string] + Container mysql.WhereMod[Q, string] + Tenant mysql.WhereNullMod[Q, string] + Region mysql.WhereNullMod[Q, string] + SpaceID mysql.WhereMod[Q, string] +} + +func (locationsSwiftWhere[Q]) AliasedAs(alias string) locationsSwiftWhere[Q] { + return buildLocationsSwiftWhere[Q](buildLocationsSwiftColumns(alias)) +} + +func buildLocationsSwiftWhere[Q mysql.Filterable](cols locationsSwiftColumns) locationsSwiftWhere[Q] { + return locationsSwiftWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + AuthURL: mysql.Where[Q, string](cols.AuthURL), + AuthVersion: mysql.Where[Q, string](cols.AuthVersion), + Username: mysql.Where[Q, string](cols.Username), + Password: mysql.Where[Q, string](cols.Password), + Container: mysql.Where[Q, string](cols.Container), + Tenant: mysql.WhereNull[Q, string](cols.Tenant), + Region: mysql.WhereNull[Q, string](cols.Region), + SpaceID: mysql.Where[Q, string](cols.SpaceID), + } +} + +func (o *LocationsSwift) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "SpaceLocationsSpace": + rel, ok := retrieved.(*LocationsSpace) + if !ok { + return fmt.Errorf("locationsSwift cannot load %T as %q", retrieved, name) + } + + o.R.SpaceLocationsSpace = rel + + if rel != nil { + rel.R.SpaceLocationsSwift = o + } + return nil + default: + return fmt.Errorf("locationsSwift has no relationship %q", name) + } +} + +type locationsSwiftPreloader struct { + SpaceLocationsSpace func(...mysql.PreloadOption) mysql.Preloader +} + +func buildLocationsSwiftPreloader() locationsSwiftPreloader { + return locationsSwiftPreloader{ + SpaceLocationsSpace: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*LocationsSpace, LocationsSpaceSlice](mysql.PreloadRel{ + Name: "SpaceLocationsSpace", + Sides: []mysql.PreloadSide{ + { + From: LocationsSwifts, + To: LocationsSpaces, + FromColumns: []string{"space_id"}, + ToColumns: []string{"uuid"}, + }, + }, + }, LocationsSpaces.Columns.Names(), opts...) + }, + } +} + +type locationsSwiftThenLoader[Q orm.Loadable] struct { + SpaceLocationsSpace func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildLocationsSwiftThenLoader[Q orm.Loadable]() locationsSwiftThenLoader[Q] { + type SpaceLocationsSpaceLoadInterface interface { + LoadSpaceLocationsSpace(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return locationsSwiftThenLoader[Q]{ + SpaceLocationsSpace: thenLoadBuilder[Q]( + "SpaceLocationsSpace", + func(ctx context.Context, exec bob.Executor, retrieved SpaceLocationsSpaceLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadSpaceLocationsSpace(ctx, exec, mods...) + }, + ), + } +} + +// LoadSpaceLocationsSpace loads the locationsSwift's SpaceLocationsSpace into the .R struct +func (o *LocationsSwift) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.SpaceLocationsSpace = nil + + related, err := o.SpaceLocationsSpace(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.SpaceLocationsSwift = o + + o.R.SpaceLocationsSpace = related + return nil +} + +// LoadSpaceLocationsSpace loads the locationsSwift's SpaceLocationsSpace into the .R struct +func (os LocationsSwiftSlice) LoadSpaceLocationsSpace(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + locationsSpaces, err := os.SpaceLocationsSpace(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range locationsSpaces { + + if !(o.SpaceID == rel.UUID) { + continue + } + + rel.R.SpaceLocationsSwift = o + + o.R.SpaceLocationsSpace = rel + break + } + } + + return nil +} + +type locationsSwiftJoins[Q dialect.Joinable] struct { + typ string + SpaceLocationsSpace modAs[Q, locationsSpaceColumns] +} + +func (j locationsSwiftJoins[Q]) aliasedAs(alias string) locationsSwiftJoins[Q] { + return buildLocationsSwiftJoins[Q](buildLocationsSwiftColumns(alias), j.typ) +} + +func buildLocationsSwiftJoins[Q dialect.Joinable](cols locationsSwiftColumns, typ string) locationsSwiftJoins[Q] { + return locationsSwiftJoins[Q]{ + typ: typ, + SpaceLocationsSpace: modAs[Q, locationsSpaceColumns]{ + c: LocationsSpaces.Columns, + f: func(to locationsSpaceColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, LocationsSpaces.Name().As(to.Alias())).On( + to.UUID.EQ(cols.SpaceID), + )) + } + + return mods + }, + }, + } +} diff --git a/database/storage_service/models/tastypie_apiaccess.bob.go b/database/storage_service/models/tastypie_apiaccess.bob.go new file mode 100644 index 0000000..b7a15a5 --- /dev/null +++ b/database/storage_service/models/tastypie_apiaccess.bob.go @@ -0,0 +1,442 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "io" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" +) + +// TastypieApiaccess is an object representing the database table. +type TastypieApiaccess struct { + ID int32 `db:"id,pk,autoincr" ` + Identifier string `db:"identifier" ` + URL string `db:"url" ` + RequestMethod string `db:"request_method" ` + Accessed uint32 `db:"accessed" ` +} + +// TastypieApiaccessSlice is an alias for a slice of pointers to TastypieApiaccess. +// This should almost always be used instead of []*TastypieApiaccess. +type TastypieApiaccessSlice []*TastypieApiaccess + +// TastypieApiaccesses contains methods to work with the tastypie_apiaccess table +var TastypieApiaccesses = mysql.NewTablex[*TastypieApiaccess, TastypieApiaccessSlice, *TastypieApiaccessSetter]("tastypie_apiaccess", buildTastypieApiaccessColumns("tastypie_apiaccess"), []string{"id"}) + +// TastypieApiaccessesQuery is a query on the tastypie_apiaccess table +type TastypieApiaccessesQuery = *mysql.ViewQuery[*TastypieApiaccess, TastypieApiaccessSlice] + +func buildTastypieApiaccessColumns(alias string) tastypieApiaccessColumns { + return tastypieApiaccessColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "identifier", "url", "request_method", "accessed", + ).WithParent("tastypie_apiaccess"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Identifier: mysql.Quote(alias, "identifier"), + URL: mysql.Quote(alias, "url"), + RequestMethod: mysql.Quote(alias, "request_method"), + Accessed: mysql.Quote(alias, "accessed"), + } +} + +type tastypieApiaccessColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Identifier mysql.Expression + URL mysql.Expression + RequestMethod mysql.Expression + Accessed mysql.Expression +} + +func (c tastypieApiaccessColumns) Alias() string { + return c.tableAlias +} + +func (tastypieApiaccessColumns) AliasedAs(alias string) tastypieApiaccessColumns { + return buildTastypieApiaccessColumns(alias) +} + +// TastypieApiaccessSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type TastypieApiaccessSetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Identifier omit.Val[string] `db:"identifier" ` + URL omit.Val[string] `db:"url" ` + RequestMethod omit.Val[string] `db:"request_method" ` + Accessed omit.Val[uint32] `db:"accessed" ` +} + +func (s TastypieApiaccessSetter) SetColumns() []string { + vals := make([]string, 0, 5) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Identifier.IsValue() { + vals = append(vals, "identifier") + } + if s.URL.IsValue() { + vals = append(vals, "url") + } + if s.RequestMethod.IsValue() { + vals = append(vals, "request_method") + } + if s.Accessed.IsValue() { + vals = append(vals, "accessed") + } + return vals +} + +func (s TastypieApiaccessSetter) Overwrite(t *TastypieApiaccess) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Identifier.IsValue() { + t.Identifier = s.Identifier.MustGet() + } + if s.URL.IsValue() { + t.URL = s.URL.MustGet() + } + if s.RequestMethod.IsValue() { + t.RequestMethod = s.RequestMethod.MustGet() + } + if s.Accessed.IsValue() { + t.Accessed = s.Accessed.MustGet() + } +} + +func (s *TastypieApiaccessSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return TastypieApiaccesses.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Identifier.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Identifier.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.URL.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.URL.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.RequestMethod.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.RequestMethod.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Accessed.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Accessed.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s TastypieApiaccessSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("tastypie_apiaccess")...) +} + +func (s TastypieApiaccessSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 5) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Identifier.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "identifier")...), + mysql.Arg(s.Identifier), + }}) + } + + if s.URL.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "url")...), + mysql.Arg(s.URL), + }}) + } + + if s.RequestMethod.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "request_method")...), + mysql.Arg(s.RequestMethod), + }}) + } + + if s.Accessed.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "accessed")...), + mysql.Arg(s.Accessed), + }}) + } + + return exprs +} + +// FindTastypieApiaccess retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindTastypieApiaccess(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*TastypieApiaccess, error) { + if len(cols) == 0 { + return TastypieApiaccesses.Query( + sm.Where(TastypieApiaccesses.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return TastypieApiaccesses.Query( + sm.Where(TastypieApiaccesses.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(TastypieApiaccesses.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// TastypieApiaccessExists checks the presence of a single record by primary key +func TastypieApiaccessExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return TastypieApiaccesses.Query( + sm.Where(TastypieApiaccesses.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after TastypieApiaccess is retrieved from the database +func (o *TastypieApiaccess) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = TastypieApiaccesses.AfterSelectHooks.RunHooks(ctx, exec, TastypieApiaccessSlice{o}) + case bob.QueryTypeInsert: + ctx, err = TastypieApiaccesses.AfterInsertHooks.RunHooks(ctx, exec, TastypieApiaccessSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = TastypieApiaccesses.AfterUpdateHooks.RunHooks(ctx, exec, TastypieApiaccessSlice{o}) + case bob.QueryTypeDelete: + ctx, err = TastypieApiaccesses.AfterDeleteHooks.RunHooks(ctx, exec, TastypieApiaccessSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the TastypieApiaccess +func (o *TastypieApiaccess) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *TastypieApiaccess) pkEQ() dialect.Expression { + return mysql.Quote("tastypie_apiaccess", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the TastypieApiaccess +func (o *TastypieApiaccess) Update(ctx context.Context, exec bob.Executor, s *TastypieApiaccessSetter) error { + _, err := TastypieApiaccesses.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single TastypieApiaccess record with an executor +func (o *TastypieApiaccess) Delete(ctx context.Context, exec bob.Executor) error { + _, err := TastypieApiaccesses.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the TastypieApiaccess using the executor +func (o *TastypieApiaccess) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := TastypieApiaccesses.Query( + sm.Where(TastypieApiaccesses.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + + *o = *o2 + + return nil +} + +// AfterQueryHook is called after TastypieApiaccessSlice is retrieved from the database +func (o TastypieApiaccessSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = TastypieApiaccesses.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = TastypieApiaccesses.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = TastypieApiaccesses.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = TastypieApiaccesses.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o TastypieApiaccessSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("tastypie_apiaccess", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o TastypieApiaccessSlice) copyMatchingRows(from ...*TastypieApiaccess) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o TastypieApiaccessSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return TastypieApiaccesses.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *TastypieApiaccess: + o.copyMatchingRows(retrieved) + case []*TastypieApiaccess: + o.copyMatchingRows(retrieved...) + case TastypieApiaccessSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a TastypieApiaccess or a slice of TastypieApiaccess + // then run the AfterUpdateHooks on the slice + _, err = TastypieApiaccesses.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o TastypieApiaccessSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return TastypieApiaccesses.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *TastypieApiaccess: + o.copyMatchingRows(retrieved) + case []*TastypieApiaccess: + o.copyMatchingRows(retrieved...) + case TastypieApiaccessSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a TastypieApiaccess or a slice of TastypieApiaccess + // then run the AfterDeleteHooks on the slice + _, err = TastypieApiaccesses.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o TastypieApiaccessSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals TastypieApiaccessSetter) error { + _, err := TastypieApiaccesses.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o TastypieApiaccessSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := TastypieApiaccesses.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o TastypieApiaccessSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := TastypieApiaccesses.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +type tastypieApiaccessWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Identifier mysql.WhereMod[Q, string] + URL mysql.WhereMod[Q, string] + RequestMethod mysql.WhereMod[Q, string] + Accessed mysql.WhereMod[Q, uint32] +} + +func (tastypieApiaccessWhere[Q]) AliasedAs(alias string) tastypieApiaccessWhere[Q] { + return buildTastypieApiaccessWhere[Q](buildTastypieApiaccessColumns(alias)) +} + +func buildTastypieApiaccessWhere[Q mysql.Filterable](cols tastypieApiaccessColumns) tastypieApiaccessWhere[Q] { + return tastypieApiaccessWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Identifier: mysql.Where[Q, string](cols.Identifier), + URL: mysql.Where[Q, string](cols.URL), + RequestMethod: mysql.Where[Q, string](cols.RequestMethod), + Accessed: mysql.Where[Q, uint32](cols.Accessed), + } +} diff --git a/database/storage_service/models/tastypie_apikey.bob.go b/database/storage_service/models/tastypie_apikey.bob.go new file mode 100644 index 0000000..fc877a8 --- /dev/null +++ b/database/storage_service/models/tastypie_apikey.bob.go @@ -0,0 +1,641 @@ +// Code generated by BobGen mysql v0.42.0. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/aarondl/opt/omit" + "github.com/stephenafamo/bob" + "github.com/stephenafamo/bob/dialect/mysql" + "github.com/stephenafamo/bob/dialect/mysql/dialect" + "github.com/stephenafamo/bob/dialect/mysql/dm" + "github.com/stephenafamo/bob/dialect/mysql/sm" + "github.com/stephenafamo/bob/dialect/mysql/um" + "github.com/stephenafamo/bob/expr" + "github.com/stephenafamo/bob/mods" + "github.com/stephenafamo/bob/orm" +) + +// TastypieApikey is an object representing the database table. +type TastypieApikey struct { + ID int32 `db:"id,pk,autoincr" ` + Key string `db:"key" ` + Created time.Time `db:"created" ` + UserID int32 `db:"user_id" ` + + R tastypieApikeyR `db:"-" ` +} + +// TastypieApikeySlice is an alias for a slice of pointers to TastypieApikey. +// This should almost always be used instead of []*TastypieApikey. +type TastypieApikeySlice []*TastypieApikey + +// TastypieApikeys contains methods to work with the tastypie_apikey table +var TastypieApikeys = mysql.NewTablex[*TastypieApikey, TastypieApikeySlice, *TastypieApikeySetter]("tastypie_apikey", buildTastypieApikeyColumns("tastypie_apikey"), []string{"id"}, []string{"user_id"}) + +// TastypieApikeysQuery is a query on the tastypie_apikey table +type TastypieApikeysQuery = *mysql.ViewQuery[*TastypieApikey, TastypieApikeySlice] + +// tastypieApikeyR is where relationships are stored. +type tastypieApikeyR struct { + UserAuthUser *AuthUser // tastypie_apikey_user_id_8c8fa920_fk_auth_user_id +} + +func buildTastypieApikeyColumns(alias string) tastypieApikeyColumns { + return tastypieApikeyColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "id", "key", "created", "user_id", + ).WithParent("tastypie_apikey"), + tableAlias: alias, + ID: mysql.Quote(alias, "id"), + Key: mysql.Quote(alias, "key"), + Created: mysql.Quote(alias, "created"), + UserID: mysql.Quote(alias, "user_id"), + } +} + +type tastypieApikeyColumns struct { + expr.ColumnsExpr + tableAlias string + ID mysql.Expression + Key mysql.Expression + Created mysql.Expression + UserID mysql.Expression +} + +func (c tastypieApikeyColumns) Alias() string { + return c.tableAlias +} + +func (tastypieApikeyColumns) AliasedAs(alias string) tastypieApikeyColumns { + return buildTastypieApikeyColumns(alias) +} + +// TastypieApikeySetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type TastypieApikeySetter struct { + ID omit.Val[int32] `db:"id,pk,autoincr" ` + Key omit.Val[string] `db:"key" ` + Created omit.Val[time.Time] `db:"created" ` + UserID omit.Val[int32] `db:"user_id" ` +} + +func (s TastypieApikeySetter) SetColumns() []string { + vals := make([]string, 0, 4) + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.Key.IsValue() { + vals = append(vals, "key") + } + if s.Created.IsValue() { + vals = append(vals, "created") + } + if s.UserID.IsValue() { + vals = append(vals, "user_id") + } + return vals +} + +func (s TastypieApikeySetter) Overwrite(t *TastypieApikey) { + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.Key.IsValue() { + t.Key = s.Key.MustGet() + } + if s.Created.IsValue() { + t.Created = s.Created.MustGet() + } + if s.UserID.IsValue() { + t.UserID = s.UserID.MustGet() + } +} + +func (s *TastypieApikeySetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return TastypieApikeys.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues( + bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.ID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.ID.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Key.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Key.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.Created.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.Created.MustGet()).WriteSQL(ctx, w, d, start) + }), bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + if !(s.UserID.IsValue()) { + return mysql.Raw("DEFAULT").WriteSQL(ctx, w, d, start) + } + return mysql.Arg(s.UserID.MustGet()).WriteSQL(ctx, w, d, start) + })) +} + +func (s TastypieApikeySetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions("tastypie_apikey")...) +} + +func (s TastypieApikeySetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 4) + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "id")...), + mysql.Arg(s.ID), + }}) + } + + if s.Key.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "key")...), + mysql.Arg(s.Key), + }}) + } + + if s.Created.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "created")...), + mysql.Arg(s.Created), + }}) + } + + if s.UserID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + mysql.Quote(append(prefix, "user_id")...), + mysql.Arg(s.UserID), + }}) + } + + return exprs +} + +// FindTastypieApikey retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindTastypieApikey(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*TastypieApikey, error) { + if len(cols) == 0 { + return TastypieApikeys.Query( + sm.Where(TastypieApikeys.Columns.ID.EQ(mysql.Arg(IDPK))), + ).One(ctx, exec) + } + + return TastypieApikeys.Query( + sm.Where(TastypieApikeys.Columns.ID.EQ(mysql.Arg(IDPK))), + sm.Columns(TastypieApikeys.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// TastypieApikeyExists checks the presence of a single record by primary key +func TastypieApikeyExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) { + return TastypieApikeys.Query( + sm.Where(TastypieApikeys.Columns.ID.EQ(mysql.Arg(IDPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after TastypieApikey is retrieved from the database +func (o *TastypieApikey) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = TastypieApikeys.AfterSelectHooks.RunHooks(ctx, exec, TastypieApikeySlice{o}) + case bob.QueryTypeInsert: + ctx, err = TastypieApikeys.AfterInsertHooks.RunHooks(ctx, exec, TastypieApikeySlice{o}) + case bob.QueryTypeUpdate: + ctx, err = TastypieApikeys.AfterUpdateHooks.RunHooks(ctx, exec, TastypieApikeySlice{o}) + case bob.QueryTypeDelete: + ctx, err = TastypieApikeys.AfterDeleteHooks.RunHooks(ctx, exec, TastypieApikeySlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the TastypieApikey +func (o *TastypieApikey) primaryKeyVals() bob.Expression { + return mysql.Arg(o.ID) +} + +func (o *TastypieApikey) pkEQ() dialect.Expression { + return mysql.Quote("tastypie_apikey", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the TastypieApikey +func (o *TastypieApikey) Update(ctx context.Context, exec bob.Executor, s *TastypieApikeySetter) error { + _, err := TastypieApikeys.Update(s.UpdateMod(), um.Where(o.pkEQ())).Exec(ctx, exec) + if err != nil { + return err + } + + s.Overwrite(o) + + return nil +} + +// Delete deletes a single TastypieApikey record with an executor +func (o *TastypieApikey) Delete(ctx context.Context, exec bob.Executor) error { + _, err := TastypieApikeys.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the TastypieApikey using the executor +func (o *TastypieApikey) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := TastypieApikeys.Query( + sm.Where(TastypieApikeys.Columns.ID.EQ(mysql.Arg(o.ID))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after TastypieApikeySlice is retrieved from the database +func (o TastypieApikeySlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = TastypieApikeys.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = TastypieApikeys.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = TastypieApikeys.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = TastypieApikeys.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o TastypieApikeySlice) pkIN() dialect.Expression { + if len(o) == 0 { + return mysql.Raw("NULL") + } + + return mysql.Quote("tastypie_apikey", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o TastypieApikeySlice) copyMatchingRows(from ...*TastypieApikey) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o TastypieApikeySlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return TastypieApikeys.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *TastypieApikey: + o.copyMatchingRows(retrieved) + case []*TastypieApikey: + o.copyMatchingRows(retrieved...) + case TastypieApikeySlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a TastypieApikey or a slice of TastypieApikey + // then run the AfterUpdateHooks on the slice + _, err = TastypieApikeys.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o TastypieApikeySlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return TastypieApikeys.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *TastypieApikey: + o.copyMatchingRows(retrieved) + case []*TastypieApikey: + o.copyMatchingRows(retrieved...) + case TastypieApikeySlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a TastypieApikey or a slice of TastypieApikey + // then run the AfterDeleteHooks on the slice + _, err = TastypieApikeys.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o TastypieApikeySlice) UpdateAll(ctx context.Context, exec bob.Executor, vals TastypieApikeySetter) error { + _, err := TastypieApikeys.Update(vals.UpdateMod(), o.UpdateMod()).Exec(ctx, exec) + + for i := range o { + vals.Overwrite(o[i]) + } + + return err +} + +func (o TastypieApikeySlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := TastypieApikeys.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o TastypieApikeySlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := TastypieApikeys.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// UserAuthUser starts a query for related objects on auth_user +func (o *TastypieApikey) UserAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + return AuthUsers.Query(append(mods, + sm.Where(AuthUsers.Columns.ID.EQ(mysql.Arg(o.UserID))), + )...) +} + +func (os TastypieApikeySlice) UserAuthUser(mods ...bob.Mod[*dialect.SelectQuery]) AuthUsersQuery { + PKArgSlice := make([]bob.Expression, len(os)) + for i, o := range os { + PKArgSlice[i] = mysql.ArgGroup(o.UserID) + } + PKArgExpr := mysql.Group(PKArgSlice...) + + return AuthUsers.Query(append(mods, + sm.Where(mysql.Group(AuthUsers.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func attachTastypieApikeyUserAuthUser0(ctx context.Context, exec bob.Executor, count int, tastypieApikey0 *TastypieApikey, authUser1 *AuthUser) (*TastypieApikey, error) { + setter := &TastypieApikeySetter{ + UserID: omit.From(authUser1.ID), + } + + err := tastypieApikey0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachTastypieApikeyUserAuthUser0: %w", err) + } + + return tastypieApikey0, nil +} + +func (tastypieApikey0 *TastypieApikey) InsertUserAuthUser(ctx context.Context, exec bob.Executor, related *AuthUserSetter) error { + var err error + + authUser1, err := AuthUsers.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachTastypieApikeyUserAuthUser0(ctx, exec, 1, tastypieApikey0, authUser1) + if err != nil { + return err + } + + tastypieApikey0.R.UserAuthUser = authUser1 + + authUser1.R.UserTastypieApikey = tastypieApikey0 + + return nil +} + +func (tastypieApikey0 *TastypieApikey) AttachUserAuthUser(ctx context.Context, exec bob.Executor, authUser1 *AuthUser) error { + var err error + + _, err = attachTastypieApikeyUserAuthUser0(ctx, exec, 1, tastypieApikey0, authUser1) + if err != nil { + return err + } + + tastypieApikey0.R.UserAuthUser = authUser1 + + authUser1.R.UserTastypieApikey = tastypieApikey0 + + return nil +} + +type tastypieApikeyWhere[Q mysql.Filterable] struct { + ID mysql.WhereMod[Q, int32] + Key mysql.WhereMod[Q, string] + Created mysql.WhereMod[Q, time.Time] + UserID mysql.WhereMod[Q, int32] +} + +func (tastypieApikeyWhere[Q]) AliasedAs(alias string) tastypieApikeyWhere[Q] { + return buildTastypieApikeyWhere[Q](buildTastypieApikeyColumns(alias)) +} + +func buildTastypieApikeyWhere[Q mysql.Filterable](cols tastypieApikeyColumns) tastypieApikeyWhere[Q] { + return tastypieApikeyWhere[Q]{ + ID: mysql.Where[Q, int32](cols.ID), + Key: mysql.Where[Q, string](cols.Key), + Created: mysql.Where[Q, time.Time](cols.Created), + UserID: mysql.Where[Q, int32](cols.UserID), + } +} + +func (o *TastypieApikey) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "UserAuthUser": + rel, ok := retrieved.(*AuthUser) + if !ok { + return fmt.Errorf("tastypieApikey cannot load %T as %q", retrieved, name) + } + + o.R.UserAuthUser = rel + + if rel != nil { + rel.R.UserTastypieApikey = o + } + return nil + default: + return fmt.Errorf("tastypieApikey has no relationship %q", name) + } +} + +type tastypieApikeyPreloader struct { + UserAuthUser func(...mysql.PreloadOption) mysql.Preloader +} + +func buildTastypieApikeyPreloader() tastypieApikeyPreloader { + return tastypieApikeyPreloader{ + UserAuthUser: func(opts ...mysql.PreloadOption) mysql.Preloader { + return mysql.Preload[*AuthUser, AuthUserSlice](mysql.PreloadRel{ + Name: "UserAuthUser", + Sides: []mysql.PreloadSide{ + { + From: TastypieApikeys, + To: AuthUsers, + FromColumns: []string{"user_id"}, + ToColumns: []string{"id"}, + }, + }, + }, AuthUsers.Columns.Names(), opts...) + }, + } +} + +type tastypieApikeyThenLoader[Q orm.Loadable] struct { + UserAuthUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildTastypieApikeyThenLoader[Q orm.Loadable]() tastypieApikeyThenLoader[Q] { + type UserAuthUserLoadInterface interface { + LoadUserAuthUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return tastypieApikeyThenLoader[Q]{ + UserAuthUser: thenLoadBuilder[Q]( + "UserAuthUser", + func(ctx context.Context, exec bob.Executor, retrieved UserAuthUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadUserAuthUser(ctx, exec, mods...) + }, + ), + } +} + +// LoadUserAuthUser loads the tastypieApikey's UserAuthUser into the .R struct +func (o *TastypieApikey) LoadUserAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.UserAuthUser = nil + + related, err := o.UserAuthUser(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.UserTastypieApikey = o + + o.R.UserAuthUser = related + return nil +} + +// LoadUserAuthUser loads the tastypieApikey's UserAuthUser into the .R struct +func (os TastypieApikeySlice) LoadUserAuthUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + authUsers, err := os.UserAuthUser(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range authUsers { + + if !(o.UserID == rel.ID) { + continue + } + + rel.R.UserTastypieApikey = o + + o.R.UserAuthUser = rel + break + } + } + + return nil +} + +type tastypieApikeyJoins[Q dialect.Joinable] struct { + typ string + UserAuthUser modAs[Q, authUserColumns] +} + +func (j tastypieApikeyJoins[Q]) aliasedAs(alias string) tastypieApikeyJoins[Q] { + return buildTastypieApikeyJoins[Q](buildTastypieApikeyColumns(alias), j.typ) +} + +func buildTastypieApikeyJoins[Q dialect.Joinable](cols tastypieApikeyColumns, typ string) tastypieApikeyJoins[Q] { + return tastypieApikeyJoins[Q]{ + typ: typ, + UserAuthUser: modAs[Q, authUserColumns]{ + c: AuthUsers.Columns, + f: func(to authUserColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, AuthUsers.Name().As(to.Alias())).On( + to.ID.EQ(cols.UserID), + )) + } + + return mods + }, + }, + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a0c571c --- /dev/null +++ b/go.mod @@ -0,0 +1,52 @@ +module gitlab.artefactual.com/dcosme/am-scripts + +go 1.26.1 + +require ( + github.com/go-sql-driver/mysql v1.9.3 + github.com/stephenafamo/bob v0.42.0 +) + +require ( + dario.cat/mergo v1.0.1 // indirect + filippo.io/edwards25519 v1.1.0 // indirect + github.com/Masterminds/goutils v1.1.1 // indirect + github.com/Masterminds/semver/v3 v3.3.0 // indirect + github.com/Masterminds/sprig/v3 v3.3.0 // indirect + github.com/aarondl/opt v0.0.0-20250607033636-982744e1bd65 // indirect + github.com/antlr4-go/antlr/v4 v4.13.1 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 // indirect + github.com/google/go-cmp v0.7.0 // indirect + github.com/google/uuid v1.6.0 // indirect + github.com/huandu/xstrings v1.5.0 // indirect + github.com/knadh/koanf/maps v0.1.1 // indirect + github.com/knadh/koanf/parsers/yaml v0.1.0 // indirect + github.com/knadh/koanf/providers/confmap v0.1.0 // indirect + github.com/knadh/koanf/providers/env v0.1.0 // indirect + github.com/knadh/koanf/providers/file v0.1.0 // indirect + github.com/knadh/koanf/v2 v2.1.0 // indirect + github.com/mitchellh/copystructure v1.2.0 // indirect + github.com/mitchellh/reflectwalk v1.0.2 // indirect + github.com/qdm12/reprint v0.0.0-20200326205758-722754a53494 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/shopspring/decimal v1.4.0 // indirect + github.com/spf13/cast v1.7.0 // indirect + github.com/stephenafamo/scan v0.7.0 // indirect + github.com/stephenafamo/sqlparser v0.0.0-20250521201114-5cfed001272d // indirect + github.com/urfave/cli/v2 v2.23.7 // indirect + github.com/volatiletech/inflect v0.0.1 // indirect + github.com/volatiletech/strmangle v0.0.6 // indirect + github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + golang.org/x/crypto v0.37.0 // indirect + golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect + golang.org/x/mod v0.24.0 // indirect + golang.org/x/sync v0.13.0 // indirect + golang.org/x/sys v0.32.0 // indirect + golang.org/x/tools v0.31.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect + mvdan.cc/gofumpt v0.7.0 // indirect +) + +tool github.com/stephenafamo/bob/gen/bobgen-mysql diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..4369d20 --- /dev/null +++ b/go.sum @@ -0,0 +1,204 @@ +dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s= +dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= +filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= +github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= +github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= +github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0= +github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= +github.com/Masterminds/sprig/v3 v3.3.0 h1:mQh0Yrg1XPo6vjYXgtf5OtijNAKJRNcTdOOGZe3tPhs= +github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSCzdgBfDb35Lz0= +github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= +github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= +github.com/aarondl/opt v0.0.0-20250607033636-982744e1bd65 h1:lbdPe4LBNmNDzeQFwNhEc88w90841qv737MI4+aXSYU= +github.com/aarondl/opt v0.0.0-20250607033636-982744e1bd65/go.mod h1:+xKBXrTAUOvrDXO5PRwIr4E1wciHY3Glgl+6OkCXknU= +github.com/antlr4-go/antlr/v4 v4.13.1 h1:SqQKkuVZ+zWkMMNkjy5FZe5mr5WURWnlpmOuzYWrPrQ= +github.com/antlr4-go/antlr/v4 v4.13.1/go.mod h1:GKmUxMtwp6ZgGwZSva4eWPC5mS6vUAmOABFgjdkM7Nw= +github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI= +github.com/containerd/errdefs v1.0.0/go.mod h1:+YBYIdtsnF4Iw6nWZhJcqGSg/dwvV7tyJ/kCkyJ2k+M= +github.com/containerd/errdefs/pkg v0.3.0 h1:9IKJ06FvyNlexW690DXuQNx2KA2cUJXx151Xdx3ZPPE= +github.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmCQvQ4GpJHEqRLVk= +github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= +github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= +github.com/containerd/platforms v0.2.1 h1:zvwtM3rz2YHPQsF2CHYM8+KtB5dvhISiXh5ZpSBQv6A= +github.com/containerd/platforms v0.2.1/go.mod h1:XHCb+2/hzowdiut9rkudds9bE5yJ7npe7dG/wG+uFPw= +github.com/cpuguy83/dockercfg v0.3.2 h1:DlJTyZGBDlXqUZ2Dk2Q3xHs/FtnooJJVaad2S9GKorA= +github.com/cpuguy83/dockercfg v0.3.2/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= +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= +github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= +github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= +github.com/docker/docker v28.2.2+incompatible h1:CjwRSksz8Yo4+RmQ339Dp/D2tGO5JxwYeqtMOEe0LDw= +github.com/docker/docker v28.2.2+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c= +github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc= +github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= +github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/ebitengine/purego v0.8.4 h1:CF7LEKg5FFOsASUj0+QwaXf8Ht6TlFxg09+S9wz0omw= +github.com/ebitengine/purego v0.8.4/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= +github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= +github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/friendsofgo/errors v0.9.2 h1:X6NYxef4efCBdwI7BgS820zFaN7Cphrmb+Pljdzjtgk= +github.com/friendsofgo/errors v0.9.2/go.mod h1:yCvFW5AkDIL9qn7suHVLiI/gH228n7PC4Pn44IGoTOI= +github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= +github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI= +github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow= +github.com/go-sql-driver/mysql v1.9.3 h1:U/N249h2WzJ3Ukj8SowVFjdtZKfu9vlLZxjPXV1aweo= +github.com/go-sql-driver/mysql v1.9.3/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU= +github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1 h1:TQcrn6Wq+sKGkpyPvppOz99zsMBaUOKXq6HSv655U1c= +github.com/go-viper/mapstructure/v2 v2.0.0-alpha.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/huandu/xstrings v1.5.0 h1:2ag3IFq9ZDANvthTwTiqSSZLjDc+BedvHPAp5tJy2TI= +github.com/huandu/xstrings v1.5.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= +github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= +github.com/knadh/koanf/maps v0.1.1 h1:G5TjmUh2D7G2YWf5SQQqSiHRJEjaicvU0KpypqB3NIs= +github.com/knadh/koanf/maps v0.1.1/go.mod h1:npD/QZY3V6ghQDdcQzl1W4ICNVTkohC8E73eI2xW4yI= +github.com/knadh/koanf/parsers/yaml v0.1.0 h1:ZZ8/iGfRLvKSaMEECEBPM1HQslrZADk8fP1XFUxVI5w= +github.com/knadh/koanf/parsers/yaml v0.1.0/go.mod h1:cvbUDC7AL23pImuQP0oRw/hPuccrNBS2bps8asS0CwY= +github.com/knadh/koanf/providers/confmap v0.1.0 h1:gOkxhHkemwG4LezxxN8DMOFopOPghxRVp7JbIvdvqzU= +github.com/knadh/koanf/providers/confmap v0.1.0/go.mod h1:2uLhxQzJnyHKfxG927awZC7+fyHFdQkd697K4MdLnIU= +github.com/knadh/koanf/providers/env v0.1.0 h1:LqKteXqfOWyx5Ab9VfGHmjY9BvRXi+clwyZozgVRiKg= +github.com/knadh/koanf/providers/env v0.1.0/go.mod h1:RE8K9GbACJkeEnkl8L/Qcj8p4ZyPXZIQ191HJi44ZaQ= +github.com/knadh/koanf/providers/file v0.1.0 h1:fs6U7nrV58d3CFAFh8VTde8TM262ObYf3ODrc//Lp+c= +github.com/knadh/koanf/providers/file v0.1.0/go.mod h1:rjJ/nHQl64iYCtAW2QQnF0eSmDEX/YZ/eNFj5yR6BvA= +github.com/knadh/koanf/v2 v2.1.0 h1:eh4QmHHBuU8BybfIJ8mB8K8gsGCD/AUQTdwGq/GzId8= +github.com/knadh/koanf/v2 v2.1.0/go.mod h1:4mnTRbZCK+ALuBXHZMjDfG9y714L7TykVnZkXbMU3Es= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= +github.com/magiconair/properties v1.8.10 h1:s31yESBquKXCV9a/ScB3ESkOjUYYv+X0rg8SYxI99mE= +github.com/magiconair/properties v1.8.10/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= +github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= +github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= +github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= +github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= +github.com/moby/go-archive v0.1.0 h1:Kk/5rdW/g+H8NHdJW2gsXyZ7UnzvJNOy6VKJqueWdcQ= +github.com/moby/go-archive v0.1.0/go.mod h1:G9B+YoujNohJmrIYFBpSd54GTUB4lt9S+xVQvsJyFuo= +github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk= +github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= +github.com/moby/sys/sequential v0.6.0 h1:qrx7XFUd/5DxtqcoH1h438hF5TmOvzC/lspjy7zgvCU= +github.com/moby/sys/sequential v0.6.0/go.mod h1:uyv8EUTrca5PnDsdMGXhZe6CCe8U/UiTWd+lL+7b/Ko= +github.com/moby/sys/user v0.4.0 h1:jhcMKit7SA80hivmFJcbB1vqmw//wU61Zdui2eQXuMs= +github.com/moby/sys/user v0.4.0/go.mod h1:bG+tYYYJgaMtRKgEmuueC0hJEAZWwtIbZTB+85uoHjs= +github.com/moby/sys/userns v0.1.0 h1:tVLXkFOxVu9A64/yh59slHVv9ahO9UIev4JZusOLG/g= +github.com/moby/sys/userns v0.1.0/go.mod h1:IHUYgu/kao6N8YZlp9Cf444ySSvCmDlmzUcYfDHOl28= +github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= +github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= +github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= +github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= +github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249 h1:NHrXEjTNQY7P0Zfx1aMrNhpgxHmow66XQtm0aQLY0AE= +github.com/nsf/jsondiff v0.0.0-20210926074059-1e845ec5d249/go.mod h1:mpRZBD8SJ55OIICQ3iWH0Yz3cjzA61JdqMLoWXeB2+8= +github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040= +github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= +github.com/qdm12/reprint v0.0.0-20200326205758-722754a53494 h1:wSmWgpuccqS2IOfmYrbRiUgv+g37W5suLLLxwwniTSc= +github.com/qdm12/reprint v0.0.0-20200326205758-722754a53494/go.mod h1:yipyliwI08eQ6XwDm1fEwKPdF/xdbkiHtrU+1Hg+vc4= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/shirou/gopsutil/v4 v4.25.5 h1:rtd9piuSMGeU8g1RMXjZs9y9luK5BwtnG7dZaQUJAsc= +github.com/shirou/gopsutil/v4 v4.25.5/go.mod h1:PfybzyydfZcN+JMMjkF6Zb8Mq1A/VcogFFg7hj50W9c= +github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k= +github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= +github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= +github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w= +github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/stephenafamo/bob v0.42.0 h1:qsiWzbEyGt6sF0ztlpBC9FWAm3UxRUXoy61H7bdk0tI= +github.com/stephenafamo/bob v0.42.0/go.mod h1:8l55917DM36gF518Iz1MHjLds7KGAfkitJfxISYlth8= +github.com/stephenafamo/fakedb v0.0.0-20221230081958-0b86f816ed97 h1:XItoZNmhOih06TC02jK7l3wlpZ0XT/sPQYutDcGOQjg= +github.com/stephenafamo/fakedb v0.0.0-20221230081958-0b86f816ed97/go.mod h1:bM3Vmw1IakoaXocHmMIGgJFYob0vuK+CFWiJHQvz0jQ= +github.com/stephenafamo/scan v0.7.0 h1:lfFiD9H5+n4AdK3qNzXQjj2M3NfTOpmWBIA39NwB94c= +github.com/stephenafamo/scan v0.7.0/go.mod h1:FhIUJ8pLNyex36xGFiazDJJ5Xry0UkAi+RkWRrEcRMg= +github.com/stephenafamo/sqlparser v0.0.0-20250521201114-5cfed001272d h1:YmPQh4pYOjqGWllnvJ2EoMZe1a8RgAyBrw4cH2FfabY= +github.com/stephenafamo/sqlparser v0.0.0-20250521201114-5cfed001272d/go.mod h1:2ATW++wFz7Mvc/N+nUtQnU+9VIGAxrn8m9JCLDSWMsQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/testcontainers/testcontainers-go v0.38.0 h1:d7uEapLcv2P8AvH8ahLqDMMxda2W9gQN1nRbHS28HBw= +github.com/testcontainers/testcontainers-go v0.38.0/go.mod h1:C52c9MoHpWO+C4aqmgSU+hxlR5jlEayWtgYrb8Pzz1w= +github.com/testcontainers/testcontainers-go/modules/mysql v0.37.0 h1:LqUos1oR5iuuzorFnSvxsHNdYdCHB/DfI82CuT58wbI= +github.com/testcontainers/testcontainers-go/modules/mysql v0.37.0/go.mod h1:vHEEHx5Kf+uq5hveaVAMrTzPY8eeRZcKcl23MRw5Tkc= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= +github.com/urfave/cli/v2 v2.23.7 h1:YHDQ46s3VghFHFf1DdF+Sh7H4RqhcM+t0TmZRJx4oJY= +github.com/urfave/cli/v2 v2.23.7/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= +github.com/volatiletech/inflect v0.0.1 h1:2a6FcMQyhmPZcLa+uet3VJ8gLn/9svWhJxJYwvE8KsU= +github.com/volatiletech/inflect v0.0.1/go.mod h1:IBti31tG6phkHitLlr5j7shC5SOo//x0AjDzaJU1PLA= +github.com/volatiletech/strmangle v0.0.6 h1:AdOYE3B2ygRDq4rXDij/MMwq6KVK/pWAYxpC7CLrkKQ= +github.com/volatiletech/strmangle v0.0.6/go.mod h1:ycDvbDkjDvhC0NUU8w3fWwl5JEMTV56vTKXzR3GeR+0= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= +github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= +github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= +github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA= +go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw= +go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ= +go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y= +go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M= +go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE= +go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs= +go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc= +golang.org/x/crypto v0.37.0 h1:kJNSjF/Xp7kU0iB2Z+9viTPMW4EqqsrywMXLJOOsXSE= +golang.org/x/crypto v0.37.0/go.mod h1:vg+k43peMZ0pUMhYmVAWysMK35e6ioLh3wB8ZCAfbVc= +golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 h1:nDVHiLt8aIbd/VzvPWN6kSOPE7+F/fNFDSXLVYkE/Iw= +golang.org/x/exp v0.0.0-20250305212735-054e65f0b394/go.mod h1:sIifuuw/Yco/y6yb6+bDNfyeQ/MdPUy/hKEMYQV17cM= +golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= +golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= +golang.org/x/sync v0.13.0 h1:AauUjRAJ9OSnvULf/ARrrVywoJDy0YS2AwQ98I37610= +golang.org/x/sync v0.13.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= +golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU= +golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk= +golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +mvdan.cc/gofumpt v0.7.0 h1:bg91ttqXmi9y2xawvkuMXyvAA/1ZGJqYAEGjXuP0JXU= +mvdan.cc/gofumpt v0.7.0/go.mod h1:txVFJy/Sc/mvaycET54pV8SW8gWxTlUuGHVEcncmNUo= diff --git a/main.go b/main.go new file mode 100644 index 0000000..9ce05a1 --- /dev/null +++ b/main.go @@ -0,0 +1,74 @@ +package main + +import ( + "database/sql" + "encoding/csv" + "encoding/json" + "flag" + "fmt" + "io" + "net/http" + "os" + "slices" + "strings" + + _ "github.com/go-sql-driver/mysql" +) + +var ( + csvPath = flag.String("csv", "aips.csv", "Path to the CSV file containing AIP names") + mysqlConnString = flag.String("mysql", "root:12345@tcp(localhost:62001)/MCP", "mysql connection string") + elasticSearch = flag.String("elastic", "http://127.0.0.1:62002", "elastic search URL") + packageNamePlaceholder = "VEV2025.624" // Placeholder for AIP package name +) + +func main() { + flag.Parse() + file, err := os.Open(*csvPath) + assertNoErr(err) + records, err := csv.NewReader(file).ReadAll() + assertNoErr(err) + + r := []string{} + for _, record := range records { + r = append(r, strings.TrimSpace(record[0])) + } + + // Elastic + elastic := *elasticSearch + "/aips/_search?" + res, err := http.Get(elastic) + assertNoErr(err) + data, err := io.ReadAll(res.Body) + assertNoErr(err) + + var er ElasticAipResponse + err = json.Unmarshal(data, &er) + assertNoErr(err) + + fmt.Printf("Total: %d\n", er.Hits.Total) + + result, err := os.OpenFile("aip_names.txt", os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0644) + for _, index := range er.Hits.Hits { + if slices.ContainsFunc(r, func(record string) bool { + return strings.Contains(index.Source.Name, record) + }) { + fmt.Println("AIP Found: " + index.Source.Name) + _, err = result.WriteString(index.Source.Name + "\n") + assertNoErr(err) + } + } +} + +func openDB(connStr string) *sql.DB { + db, err := sql.Open("mysql", connStr) + assertNoErr(err) + err = db.Ping() + assertNoErr(err) + return db +} + +func assertNoErr(err error) { + if err != nil { + panic(err) + } +} diff --git a/types.go b/types.go new file mode 100644 index 0000000..4ba9e20 --- /dev/null +++ b/types.go @@ -0,0 +1,40 @@ +package main + +type ElasticAipResponse struct { + Took int `json:"took"` + TimedOut bool `json:"timed_out"` + Shards struct { + Total int `json:"total"` + Successful int `json:"successful"` + Skipped int `json:"skipped"` + Failed int `json:"failed"` + } `json:"_shards"` + Hits struct { + Total int `json:"total"` + MaxScore float64 `json:"max_score"` + Hits []struct { + Index string `json:"_index"` + Type string `json:"_type"` + ID string `json:"_id"` + Score float64 `json:"_score"` + Source struct { + UUID string `json:"uuid"` + Name string `json:"name"` + FilePath string `json:"filePath"` + Size float64 `json:"size"` + FileCount int `json:"file_count"` + Origin string `json:"origin"` + Created int `json:"created"` + Aicid any `json:"AICID"` + IsPartOf any `json:"isPartOf"` + CountAIPsinAIC any `json:"countAIPsinAIC"` + Identifiers []any `json:"identifiers"` + TransferMetadata []any `json:"transferMetadata"` + Encrypted bool `json:"encrypted"` + Accessionids []any `json:"accessionids"` + Status string `json:"status"` + Location string `json:"location"` + } `json:"_source"` + } `json:"hits"` + } `json:"hits"` +}