Reputation: 133
How do I generate SQL code for a SQLite3 database somehow dynamically with something like a template engine? I'm new to this and I'm using jinja2 to generate HTML. Could jinja2 possibly be used for such a purpose as well, if so, is that a good idea? I would like my program to save all the data (attribute values of instances of various classes) before it stops running.
Upvotes: 2
Views: 3216
Reputation: 10274
PugSQL is described as: a simple Python interface for using parameterized SQL, in files, with any SQLAlchemy-supported database.
It is a template engine in that parameters are passed into SQL, from which python functions are created. It is a powerful idea/approach borrowed from HugSQL and YesQL (Clojure implementations).
Upvotes: 0
Reputation: 925
check out https://pypi.python.org/pypi/jinjasql/0.1.6 it seems to basically just apply jinja2 to SQL templates. I haven't played with it much yet but was just asking the same question and came upon this.
Upvotes: 3