sripathikrishnan / jinjasql

Template Language for SQL with Automatic Bind Parameter Extraction
MIT License
807 stars 88 forks source link

Docs: when to use jinjasql #40

Open robertlagrant opened 3 years ago

robertlagrant commented 3 years ago

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 commented 2 years ago

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!