(sorry for top posting) There are various SQL abstraction layers for this. I have only used Sqlalchemy. This package has two APIs: query and ORM. You might want to look at the query API. This is closer to SQL than ORM. You can use straight(obj) to inspect the SQL that's emitted ________________________________ From: Tutor <tutor-bounces+sjeik_appie=hotmail....@python.org> on behalf of boB Stepp <robertvst...@gmail.com> Sent: Tuesday, September 12, 2017 7:05:39 PM To: tutor Subject: [Tutor] How to write database-agnostic python code? (Is this even possible?)
As I continue to read about SQL, one thing jumps out: There are many differences between how SQL statements are implemented among the different database products. Even for relatively simple, straightforward things like field concatenation. One DB might use "||" as the operator. Another uses "+". Yet another only uses a "CONCAT" function. This is crazy! It almost seems like I would need to write a DB-translator class that takes a SQL statement (In some DB's version) and the target DB as inputs, and then translates the statement into that DB's particular usage of SQL. So how does one write one's python program to be DB-agnostic? And if this is impossible, then what is the best way to structure the overall program to isolate this SQL-specific stuff by itself, insofar as possible, so any migrations to a new DB type is as easy as possible? -- boB _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor