views:

45

answers:

1

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.

A: 

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
  • Cheetah - The Python-Powered Template Engine
    • Using Cheetah templates to make multiples outputs
Edward J. Stembler