TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: JinjaSQL – Generate SQL Queries using a Jinja Template

77 pointsby ksriover 8 years ago

14 comments

cygnedover 8 years ago
Looks interesting!<p>When we switched to Clojure (from nodejs), we decided against any kind of ORM and use HugSQL which allows us to write &quot;plain SQL&quot; in .sql files while still using parameters.
anshum4nover 8 years ago
Would be great if you can put in some examples where we can optimise parametric queries using this. One common instance is IN queries where if the number of params for IN clause is small, it might make sense to blow it up into multiple equals clauses, allowing better use of indexes. MySQL query optimiser is horrible with IN clauses and causes table-scans. I have seen table scans and skipping other indexes even when IN clause has zero cardinality (in which case its better to just remove it altogether).<p>Couldn&#x27;t immediately think of other cases, but that one example sounds useful for this.
评论 #12910955 未加载
adambrattover 8 years ago
Because we totally needed stored procedures to be re-implemented outside of the database in a templating language. &#x2F;s
评论 #12874617 未加载
gregopetover 8 years ago
Groovy has had similar functionality in its standard library for years now, very handy!
评论 #12876725 未加载
joaomsaover 8 years ago
Can you interpolate table and column names? Those usually aren&#x27;t amenable to change in prepared statements
评论 #12872162 未加载
asabilover 8 years ago
What about using prepared statements?
评论 #12871410 未加载
评论 #12871509 未加载
评论 #12871879 未加载
评论 #12871699 未加载
tkyjonathanover 8 years ago
This is good. SQL templates are usually much faster for database queries than using ORMs.
评论 #12871984 未加载
zubairqover 8 years ago
Very nice. I made something similar a while back:<p><a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=CzwikfCAdws" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=CzwikfCAdws</a>
johnwheelerover 8 years ago
Looks like a fantastic use of Jinja templates. This is cool.
cauterizedover 8 years ago
How does this protect against SQL injection attacks?
评论 #12871860 未加载
bradmwalkerover 8 years ago
How is this better than SQLAlchemy Core?
mhdover 8 years ago
Hmm, no convenience macros for common SQL situations (e.g. building WHERE-AND parts out of arrays)?
评论 #12871871 未加载
seabrookmxover 8 years ago
Python 2.x only?
评论 #12871516 未加载
评论 #12910980 未加载
lightlyusedover 8 years ago
Reminds me of mybatis.