2

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.

2
  • 2
    You're looking for ORMs - Object Relational Mappers. SO isn't the place for software recommendations however. Commented Dec 6, 2015 at 23:33
  • Also it doesn't really sound like you want a database; surely serializing to JSON or another format (ex. using Python's json module) would be easier? Commented Dec 7, 2015 at 0:42

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Note there is a very dangerous infinite loop bug in this library: github.com/hashedin/jinjasql/pull/17
For posterity, the infinite loop bug has been resolved, thanks @BenRudolph!
0

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.