Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Adding custom table properties to sqlboiler.toml #865
Comments
|
Hi there @wilberto-montoya-vertiv. Thank you for following our development processes closely by opening this issue before a PR. The goal of the sqlboiler generated models is to create a one-to-one database-to-Go-struct mapping. Adding custom properties isn't supported on purpose. We have tools that support use cases like this though. Have you taken a look at hooks in the README? |
|
Thank you Aaron for the quick response
Yes I am also using hooks but the functionality I am looking is different than a code that is executed before or after insert or update. What I need is something similar to Eclipselink additional criteria
http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Mapping/Additional_Criteria
Basically is a filter that is associated with an specific table (not all tables in the schema) I already have this implemented in my custom templates. But I need a way to indicate to the templates which tables are the ones that require this additional criteria and which ones no. this part need to be passed someway by sqlboiler.toml
I think Additional criteria is very useful but seems a requirement more difficult to be taken, and that is the reason only suggested to take the custom properties that is the part I already changed in sqlboiler code.
Let me know what you think about this
Wilberto Montoya
PS: There is a hook after select but that will allow me to filter the records AFTER the query was executed that will generate issue with paginations and also will not perform well with queries to large tables, already tested performance scenarios with this approach.
From: Aaron L <notifications@github.com>
Sent: Monday, November 16, 2020 9:29 PM
To: volatiletech/sqlboiler <sqlboiler@noreply.github.com>
Cc: Montoya, Wilberto <Wilberto.Montoya@vertiv.com>; Mention <mention@noreply.github.com>
Subject: [ExternalEmail] Re: [volatiletech/sqlboiler] Adding custom table properties to sqlboiler.toml (#865)
Hi there @wilberto-montoya-vertiv<https://github.com/wilberto-montoya-vertiv>. Thank you for following our development processes closely by opening this issue before a PR.
The goal of the sqlboiler generated models is to create a one-to-one database-to-Go-struct mapping. Adding custom properties isn't supported on purpose.
We have tools that support use cases like this though. Have you taken a look at hooks in the README?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#865 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AQOFEUBZZDHASUJUT4IUW2LSQHNXZANCNFSM4TXIPZNQ>.
CONFIDENTIALITY NOTICE: This e-mail and any files transmitted with it are intended solely for the use of the individual or entity to whom they are addressed and may contain confidential and privileged information protected by law. If you received this e-mail in error, any review, use, dissemination, distribution, or copying of the e-mail is strictly prohibited. Please notify the sender immediately by return e-mail and delete all copies from your system.
|
This is a new feature not really an error but the CONTRIBUTING.md requires me to open a new PR
What version of SQLBoiler are you using (
sqlboiler --version)?SQLBoiler V4.2.0
What is your database and version (eg. Postgresql 10)
Postgres 12
If this happened at generation time what was the full SQLBoiler command you used to generate your models? (if not applicable leave blank)
Yes the feature is required at generation time when I use cystom templates
sqlboiler -c ..\boil\sqlboiler.toml -o ..\boil\repository psql --templates .\templates
If this happened at runtime what code produced the issue? (if not applicable leave blank)
no runtime
What is the output of the command above with the
-dflag added to it? (Provided you are comfortable sharing this, it contains a blueprint of your schema)no error return because is a new feature
Please provide a relevant database schema so we can replicate your issue (Provided you are comfortable sharing this)
not specific to a db schema but to the template generation
Further information. What did you do, what did you expect?
When I writing/modifying templates I need a way to add a custom property to a table. by example, in my case, I need to add a security (access right) check at query time to filter the number of records the table returns. This feature is specific for some tables so I need a flag indicating if table1 support access rights check and table2 does not. something like this:
pkgname = "repository"
output = "pkg/repository"
add-global-variants = true
wipe = true
no-tests = false
[psql]
dbname = "auth"
host = "localhost"
port = 5432
user = "postgres"
pass = "xxxxxx"
sslmode = "disable"
[custom.tables.user]
needs_auth = true
auth_column = "id"
[aliases.tables.resourcegroup.relationships.resourcegroup_children_fkey]
AuthColumn = "Children"
foreign = "Parent"
As you can see the whole [custom.tables.XXXX] is a new section where I can pass custom properties to templates, then in my custom template I can retrieve the values just like any other table property:
...
{{- $authCol := .Custom.Value .Table.Name "auth_column" -}}
....
func (q {{$alias.DownSingular}}Query) ApplyAuthorizationModifier(ctx context.Context) {
qm.InnerJoin("{{printf $authFunction $authCol}}", pq.Array(ctx.Value("usergroups")) ,ctx.Value("accessrigth")).Apply(q.Query)
}
...