What are the viable database abstraction layers for Python

后端 未结 8 955
遇见更好的自我
遇见更好的自我 2020-12-28 17:51

I\'m starting to get involved in an open source project Gramps which is exploring switching their backend from BSDDB to a relational database. Either SQLite or MySQL we have

8条回答
  •  梦谈多话
    2020-12-28 18:12

    Look very closely at SQLAlchemy.

    You can test and develop with SQLite.

    You can go into production with MySQL -- making essentially no changes to your applications.

    The DB-API, while widely adhered-to, has enough flexibility that (1) you aren't insulated from SQL variation in the underlying RDBMS and (2) there are still DB driver-specific features that are hard to hide.

    Another good ORM layer is the ORM that's part of Django. You can (with a little effort) use just the Django ORM without using the rest of the Django web framework.

    Use an ORM Layer (SQLAlchemy or SQLObject) in preference to DB-API.

    Why? Your model should be a solid, clear, well-thought-out OO model. The relational mapping should come second after the object model. SQLAlchemy makes this a reasonable approach.

    A "DB Abstraction Layer" will happen in the normal course of events. Indeed, because of DB-API (as used by SQLAlchemy) you gave two abstraction layers: ORM and DB-API.

提交回复
热议问题