开发者

SQL templating engine to mix SQL with dynamic language? (similar to Ruby's erb)

Has anyone comes across a SQL templating engine which allows one to mix SQL with a dynamic language like Ruby or Python?

I'm looking for something similar to Ruby erb templates. For example, in Ruby on Rails you can have various templates for a view:

customers.html.erb (html + ruby)

customers.js.erb (javascript + ruby)

Though I want something like:

customers.sql.erb

The output could be a开发者_开发知识库 text string result of the ad-hoc SQL mixed with Ruby code. Or even, if it's Python-based that's fine too.


Well, I found out that Ruby's erb works just fine for a SQL template. I was able to use it very easily in my Rails 3 project.

I also found that Python has a templating engine, Cheetah, which can do the same thing.

References

  • An Introduction to ERB Templating
    • Class: ERB (RDoc Documentation)
  • Cheetah - The Python-Powered Template Engine
    • Using Cheetah templates to make multiples outputs
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜