Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support non-string parameters and default values #149

Open
ipamo opened this issue Mar 25, 2022 · 1 comment
Open

Support non-string parameters and default values #149

ipamo opened this issue Mar 25, 2022 · 1 comment

Comments

@ipamo
Copy link
Contributor

ipamo commented Mar 25, 2022

Passing non-string parameters and default values can be achieved today using something like:

select *
where grade >= cast(%(grade)s as integer)
and is_allowed = cast(coalesce(nullif(%(is_allowed)s,''), 'true') as boolean)

But this is not very readable. Would be nice to support some other patterns, for example:

select *
where grade >= %(grade)d
and is_allowed = %(is_allowed:true)b

I know that psycopg2 supports only string parameters, but it does not seem too difficult to manually handle simple cases (like numbers and booleans) while still caring about SQL injections.

For now, I've proposed pull request #148 to refactor the named-parameter feature within the library, so that developpers can easily extend it according to their needs. That would be usefull in any case.

I think it would also be usefull that simple cases (like those mentionned above) be part of the library. What do you think?

@ipamo
Copy link
Contributor Author

ipamo commented Mar 28, 2022

Implementation example: ExtendedParameter.

Activation in settings.py using DASHBOARD_PARAMETER_CLASS = 'django_sql_dashboard.extensions.ExtendedParameter'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant