Add SS and MCP databases
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
*.csv
|
||||||
|
.db
|
||||||
|
*.txt
|
||||||
92
README.md
92
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.
|
|
||||||
|
|||||||
30
bobgen.yaml
Normal file
30
bobgen.yaml
Normal file
@@ -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
|
||||||
26
database/mcp/dberrors/administration_settings.bob.go
Normal file
26
database/mcp/dberrors/administration_settings.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/auth_group.bob.go
Normal file
26
database/mcp/dberrors/auth_group.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/auth_group_permissions.bob.go
Normal file
26
database/mcp/dberrors/auth_group_permissions.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/auth_permission.bob.go
Normal file
26
database/mcp/dberrors/auth_permission.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/auth_user.bob.go
Normal file
26
database/mcp/dberrors/auth_user.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/auth_user_groups.bob.go
Normal file
26
database/mcp/dberrors/auth_user_groups.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/auth_user_user_permissions.bob.go
Normal file
26
database/mcp/dberrors/auth_user_user_permissions.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
36
database/mcp/dberrors/bob_errors.bob.go
Normal file
36
database/mcp/dberrors/bob_errors.bob.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
9
database/mcp/dberrors/bob_main.bob_test.go
Normal file
9
database/mcp/dberrors/bob_main.bob_test.go
Normal file
@@ -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]
|
||||||
17
database/mcp/dberrors/django_admin_log.bob.go
Normal file
17
database/mcp/dberrors/django_admin_log.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/django_content_type.bob.go
Normal file
26
database/mcp/dberrors/django_content_type.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
17
database/mcp/dberrors/django_migrations.bob.go
Normal file
17
database/mcp/dberrors/django_migrations.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
17
database/mcp/dberrors/django_session.bob.go
Normal file
17
database/mcp/dberrors/django_session.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/django_site.bob.go
Normal file
26
database/mcp/dberrors/django_site.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_archipelago.bob.go
Normal file
26
database/mcp/dberrors/locations_archipelago.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_arkivum.bob.go
Normal file
26
database/mcp/dberrors/locations_arkivum.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
17
database/mcp/dberrors/locations_async.bob.go
Normal file
17
database/mcp/dberrors/locations_async.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
17
database/mcp/dberrors/locations_callback.bob.go
Normal file
17
database/mcp/dberrors/locations_callback.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_dataverse.bob.go
Normal file
26
database/mcp/dberrors/locations_dataverse.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_dspace.bob.go
Normal file
26
database/mcp/dberrors/locations_dspace.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_dspacerest.bob.go
Normal file
26
database/mcp/dberrors/locations_dspacerest.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_duracloud.bob.go
Normal file
26
database/mcp/dberrors/locations_duracloud.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
17
database/mcp/dberrors/locations_event.bob.go
Normal file
17
database/mcp/dberrors/locations_event.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_fedora.bob.go
Normal file
26
database/mcp/dberrors/locations_fedora.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_file.bob.go
Normal file
26
database/mcp/dberrors/locations_file.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
17
database/mcp/dberrors/locations_fixitylog.bob.go
Normal file
17
database/mcp/dberrors/locations_fixitylog.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_gpg.bob.go
Normal file
26
database/mcp/dberrors/locations_gpg.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_localfilesystem.bob.go
Normal file
26
database/mcp/dberrors/locations_localfilesystem.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_location.bob.go
Normal file
26
database/mcp/dberrors/locations_location.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_location_replicators.bob.go
Normal file
26
database/mcp/dberrors/locations_location_replicators.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
17
database/mcp/dberrors/locations_locationpipeline.bob.go
Normal file
17
database/mcp/dberrors/locations_locationpipeline.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_lockssomatic.bob.go
Normal file
26
database/mcp/dberrors/locations_lockssomatic.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_nfs.bob.go
Normal file
26
database/mcp/dberrors/locations_nfs.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_offlinereplicastaging.bob.go
Normal file
26
database/mcp/dberrors/locations_offlinereplicastaging.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_package.bob.go
Normal file
26
database/mcp/dberrors/locations_package.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_packagedownloadtask.bob.go
Normal file
26
database/mcp/dberrors/locations_packagedownloadtask.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_pipeline.bob.go
Normal file
26
database/mcp/dberrors/locations_pipeline.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_pipelinelocalfs.bob.go
Normal file
26
database/mcp/dberrors/locations_pipelinelocalfs.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_rclone.bob.go
Normal file
26
database/mcp/dberrors/locations_rclone.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_s3.bob.go
Normal file
26
database/mcp/dberrors/locations_s3.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_space.bob.go
Normal file
26
database/mcp/dberrors/locations_space.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/locations_swift.bob.go
Normal file
26
database/mcp/dberrors/locations_swift.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
17
database/mcp/dberrors/tastypie_apiaccess.bob.go
Normal file
17
database/mcp/dberrors/tastypie_apiaccess.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
26
database/mcp/dberrors/tastypie_apikey.bob.go
Normal file
26
database/mcp/dberrors/tastypie_apikey.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
396
database/mcp/models/administration_settings.bob.go
Normal file
396
database/mcp/models/administration_settings.bob.go
Normal file
@@ -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),
|
||||||
|
}
|
||||||
|
}
|
||||||
795
database/mcp/models/auth_group.bob.go
Normal file
795
database/mcp/models/auth_group.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
787
database/mcp/models/auth_group_permissions.bob.go
Normal file
787
database/mcp/models/auth_group_permissions.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
1016
database/mcp/models/auth_permission.bob.go
Normal file
1016
database/mcp/models/auth_permission.bob.go
Normal file
File diff suppressed because it is too large
Load Diff
1572
database/mcp/models/auth_user.bob.go
Normal file
1572
database/mcp/models/auth_user.bob.go
Normal file
File diff suppressed because it is too large
Load Diff
787
database/mcp/models/auth_user_groups.bob.go
Normal file
787
database/mcp/models/auth_user_groups.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
787
database/mcp/models/auth_user_user_permissions.bob.go
Normal file
787
database/mcp/models/auth_user_user_permissions.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
146
database/mcp/models/bob_joins.bob.go
Normal file
146
database/mcp/models/bob_joins.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
203
database/mcp/models/bob_loaders.bob.go
Normal file
203
database/mcp/models/bob_loaders.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
141
database/mcp/models/bob_types.bob_test.go
Normal file
141
database/mcp/models/bob_types.bob_test.go
Normal file
@@ -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{}
|
||||||
156
database/mcp/models/bob_where.bob.go
Normal file
156
database/mcp/models/bob_where.bob.go
Normal file
@@ -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),
|
||||||
|
}
|
||||||
|
}
|
||||||
913
database/mcp/models/django_admin_log.bob.go
Normal file
913
database/mcp/models/django_admin_log.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
823
database/mcp/models/django_content_type.bob.go
Normal file
823
database/mcp/models/django_content_type.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
419
database/mcp/models/django_migrations.bob.go
Normal file
419
database/mcp/models/django_migrations.bob.go
Normal file
@@ -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),
|
||||||
|
}
|
||||||
|
}
|
||||||
395
database/mcp/models/django_session.bob.go
Normal file
395
database/mcp/models/django_session.bob.go
Normal file
@@ -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),
|
||||||
|
}
|
||||||
|
}
|
||||||
394
database/mcp/models/django_site.bob.go
Normal file
394
database/mcp/models/django_site.bob.go
Normal file
@@ -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),
|
||||||
|
}
|
||||||
|
}
|
||||||
664
database/mcp/models/locations_archipelago.bob.go
Normal file
664
database/mcp/models/locations_archipelago.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
666
database/mcp/models/locations_arkivum.bob.go
Normal file
666
database/mcp/models/locations_arkivum.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
517
database/mcp/models/locations_async.bob.go
Normal file
517
database/mcp/models/locations_async.bob.go
Normal file
@@ -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),
|
||||||
|
}
|
||||||
|
}
|
||||||
540
database/mcp/models/locations_callback.bob.go
Normal file
540
database/mcp/models/locations_callback.bob.go
Normal file
@@ -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),
|
||||||
|
}
|
||||||
|
}
|
||||||
712
database/mcp/models/locations_dataverse.bob.go
Normal file
712
database/mcp/models/locations_dataverse.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
714
database/mcp/models/locations_dspace.bob.go
Normal file
714
database/mcp/models/locations_dspace.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
880
database/mcp/models/locations_dspacerest.bob.go
Normal file
880
database/mcp/models/locations_dspacerest.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
688
database/mcp/models/locations_duracloud.bob.go
Normal file
688
database/mcp/models/locations_duracloud.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
1180
database/mcp/models/locations_event.bob.go
Normal file
1180
database/mcp/models/locations_event.bob.go
Normal file
File diff suppressed because it is too large
Load Diff
664
database/mcp/models/locations_fedora.bob.go
Normal file
664
database/mcp/models/locations_fedora.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
789
database/mcp/models/locations_file.bob.go
Normal file
789
database/mcp/models/locations_file.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
667
database/mcp/models/locations_fixitylog.bob.go
Normal file
667
database/mcp/models/locations_fixitylog.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
616
database/mcp/models/locations_gpg.bob.go
Normal file
616
database/mcp/models/locations_gpg.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
592
database/mcp/models/locations_localfilesystem.bob.go
Normal file
592
database/mcp/models/locations_localfilesystem.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
1705
database/mcp/models/locations_location.bob.go
Normal file
1705
database/mcp/models/locations_location.bob.go
Normal file
File diff suppressed because it is too large
Load Diff
787
database/mcp/models/locations_location_replicators.bob.go
Normal file
787
database/mcp/models/locations_location_replicators.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
787
database/mcp/models/locations_locationpipeline.bob.go
Normal file
787
database/mcp/models/locations_locationpipeline.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
762
database/mcp/models/locations_lockssomatic.bob.go
Normal file
762
database/mcp/models/locations_lockssomatic.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
688
database/mcp/models/locations_nfs.bob.go
Normal file
688
database/mcp/models/locations_nfs.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
592
database/mcp/models/locations_offlinereplicastaging.bob.go
Normal file
592
database/mcp/models/locations_offlinereplicastaging.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
2799
database/mcp/models/locations_package.bob.go
Normal file
2799
database/mcp/models/locations_package.bob.go
Normal file
File diff suppressed because it is too large
Load Diff
787
database/mcp/models/locations_package_related_packages.bob.go
Normal file
787
database/mcp/models/locations_package_related_packages.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
879
database/mcp/models/locations_packagedownloadtask.bob.go
Normal file
879
database/mcp/models/locations_packagedownloadtask.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
712
database/mcp/models/locations_packagedownloadtaskfile.bob.go
Normal file
712
database/mcp/models/locations_packagedownloadtaskfile.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
1108
database/mcp/models/locations_pipeline.bob.go
Normal file
1108
database/mcp/models/locations_pipeline.bob.go
Normal file
File diff suppressed because it is too large
Load Diff
688
database/mcp/models/locations_pipelinelocalfs.bob.go
Normal file
688
database/mcp/models/locations_pipelinelocalfs.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
640
database/mcp/models/locations_rclone.bob.go
Normal file
640
database/mcp/models/locations_rclone.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
712
database/mcp/models/locations_s3.bob.go
Normal file
712
database/mcp/models/locations_s3.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
3612
database/mcp/models/locations_space.bob.go
Normal file
3612
database/mcp/models/locations_space.bob.go
Normal file
File diff suppressed because it is too large
Load Diff
762
database/mcp/models/locations_swift.bob.go
Normal file
762
database/mcp/models/locations_swift.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
442
database/mcp/models/tastypie_apiaccess.bob.go
Normal file
442
database/mcp/models/tastypie_apiaccess.bob.go
Normal file
@@ -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),
|
||||||
|
}
|
||||||
|
}
|
||||||
641
database/mcp/models/tastypie_apikey.bob.go
Normal file
641
database/mcp/models/tastypie_apikey.bob.go
Normal file
@@ -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
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
26
database/storage_service/dberrors/auth_group.bob.go
Normal file
26
database/storage_service/dberrors/auth_group.bob.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user