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

Docs: when to use jinjasql #40

Open
robertlagrant opened this issue Jul 2, 2021 · 1 comment
Open

Docs: when to use jinjasql #40

robertlagrant opened this issue Jul 2, 2021 · 1 comment

Comments

@robertlagrant
Copy link

Just based on this section:

JinjaSQL is not meant to replace your ORM. ORMs like those provided by SQLAlchemy or Django are great for a variety of use cases, and should be the default in most cases. But there are a few use cases where you really need the power of SQL.

Use JinjaSQL for -

Reporting, business intelligence or dashboard like use cases
When you need aggregation/group by
Use cases that require data from multiple tables
Migration scripts & bulk updates that would benefit from macros
In all other use cases, you should reach to your ORM instead of writing SQL/JinjaSQL.

It would be good to know why this would be better than SQLAlchemy (I'm less familiar with Django's ORM) - some examples: SQLAlchemy has Group By support, you can get data from multiple tables using it, and you can dynamically build queries using it. Also it has the core API as a lower level SQL DSL.

Thanks!

@sripathikrishnan
Copy link
Owner

Yes, SQLAlchemy is great. In general, if your use case can be met with SQLAlchemy core, then you really should use it.

There are times when a report or a transformation needs significantly complex queries. You want to incrementally work on the query, look at performance, make tweaks and so on. Once you have the final working query - it is much simpler to put into a JinjaSQL template, than to take that monstrosity and convert it into equivalent SQLAlchemy core.

Your mileage may vary!

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

2 participants