Skip to content

Adding custom table properties to sqlboiler.toml #865

Open
@wilberto-montoya-vertiv

Description

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 -d flag 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)
}
...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions