Programming practice: How to separate concerns regarding sql access (in python)?

78 views Asked by At

In python I want to handle all SQL accesses through a separate library sql.py; only this library creates the SQl queries and makes the queries the database. Is this meaningful?

I have another python-module data.py that represents some data and contains some logic, and that does not know about how the data is stored in the database. On the other hand, sql.py does not know of any structure of data.py.

Now to efficiently update some data in the database I need to construct a list of multiple queries that are passed on to the database before committing. But where to do that? I can either make this list of queries in data.py, but then data.py knows something about the structure of the database. Or I do this in sql.py, but then sql.py needs to know something about the structure of data.py. How to do this 'right'?

0

There are 0 answers