|
|
|
|
|
by sologoub
3321 days ago
|
|
If I read the docs correctly on JinjaSQL, it essentially allows you parameterize your queries, but doesn't let you build them dynamically like SQLAlchemy would. Can someone comment on what's the benefit of this, as opposed to using parameterization and SQL-injection protections offered by say SQLAlchemy or other similar tools? |
|
There comes a time when you need the power of sql, and an ORM gets in the way. Think unions, sql functions, group by, more complex sql. Think dynamically generated sql queries based on some data structure.
In such cases, you have to keep track of how many variables you are capturing in the query, and then manually bind them.
Jinjasql is just a query generator. At the end of the day, it doesn't actually execute the query. You take the query it generates, and the array of parameters it gives - and then execute it using traditional means using bind parameters.
This approach gives you the power of a template language to generate the query. You can create reusable macros, conditionals and other features that a template language provides.