[Tutor] How to write database-agnostic python code? (Is this even possible?)
Mark Lawrence
breamoreboy at yahoo.co.uk
Thu Sep 14 00:33:06 EDT 2017
On 14/09/2017 00:51, Cameron Simpson wrote:
>
> Secondly, there's SQLAlchemy. It knows the dialects and asks you to
> write "native" looking python syntax for selects etc. So stuff like:
>
> db_conn.select(t.col1 == 9 and t.col2 == 10)
>
> where "t" is a "table" object it has handed you. I believe these are
> just special objects with attributes for columns and the right __eq__
> etc dunder methods to compute the correct SQL syntax. No escaping or
> param substitution in your own code. It also has an ORM, which I've not
> used.
>
> Cheers,
> Cameron Simpson <cs at cskk.id.au> (formerly cs at zip.com.au)
SQLAlchemy isn't the only Python ORM of course. There is a useful
little article about ORMs and their availability here
https://www.fullstackpython.com/object-relational-mappers-orms.html. A
more detailed comparison is given here
http://pythoncentral.io/sqlalchemy-vs-orms/ which refers to storm, which
is only mentioned in passing in the first link. I've successfully used
peewee, I can't really comment on the others.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
---
This email has been checked for viruses by AVG.
http://www.avg.com
More information about the Tutor
mailing list