TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

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

77 点作者 ksri超过 8 年前

14 条评论

cygned超过 8 年前
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.
anshum4n超过 8 年前
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 未加载
adambratt超过 8 年前
Because we totally needed stored procedures to be re-implemented outside of the database in a templating language. &#x2F;s
评论 #12874617 未加载
gregopet超过 8 年前
Groovy has had similar functionality in its standard library for years now, very handy!
评论 #12876725 未加载
joaomsa超过 8 年前
Can you interpolate table and column names? Those usually aren&#x27;t amenable to change in prepared statements
评论 #12872162 未加载
asabil超过 8 年前
What about using prepared statements?
评论 #12871410 未加载
评论 #12871509 未加载
评论 #12871879 未加载
评论 #12871699 未加载
tkyjonathan超过 8 年前
This is good. SQL templates are usually much faster for database queries than using ORMs.
评论 #12871984 未加载
zubairq超过 8 年前
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>
johnwheeler超过 8 年前
Looks like a fantastic use of Jinja templates. This is cool.
cauterized超过 8 年前
How does this protect against SQL injection attacks?
评论 #12871860 未加载
bradmwalker超过 8 年前
How is this better than SQLAlchemy Core?
mhd超过 8 年前
Hmm, no convenience macros for common SQL situations (e.g. building WHERE-AND parts out of arrays)?
评论 #12871871 未加载
seabrookmx超过 8 年前
Python 2.x only?
评论 #12871516 未加载
评论 #12910980 未加载
lightlyused超过 8 年前
Reminds me of mybatis.