Mixing SQLAlchemy and Django in a Python codebase and maintaining transaction integrity

I have a project in which I would like (need?) To mix SQLAlchemy models, Django models and the corresponding ORMs in the same web code base. I would like to get the default atomic queries and associate the SQLAlchemy transaction lifecycle with the Django query and the Django transaction manager.

Is there prior art how to force SQLAlchemy to use Django / connections and transaction mechanisms or vice versa?

What would be a good starting point for such integration? What restrictions exist, for example, if you try to reuse the same database connection?

To narrow down the problem:

  • Django ORM and SQLAlchemy ORM will not touch the same tables

  • At the first stage, I do not care that when the HTTP request ends, both transaction managers commit in a somewhat consistent way, for example. if Django commits a transaction SQLAlchemy also does

  • How can I say that SQLAlchemy uses the database connection configured for Django?

  • Can I associate a SQLAlchemy session with a Django transaction manager? When Django opens a database connection, could I open a new SQLAlchemy session and associate it with Django's open transactions? When Django commits a transaction, I can signal SQLAlchemy to clear its stuff so that it goes through the same cmmit. Django 1.6 introduced new atomic transaction semantics, so this might help.

+4
1

. , . SQLAlchemy Django .

Django ORM Active Record, . , SQL save(). , .

SQLAlchemy Data Mapper, , , . , , . , SQLAlchemy Python, Unit of Work, SQL . , , .

Django, , Flask SQLAlchemy, , , Django ORM SQLAlchemy. , save(), , - , Django-ORM, SQLAlchemy. , .

SQLAlchemy -- ActiveRecord, , , .

, , SQLAlchemy , , SQLAlchemy SQLAlchemy, , Django SQLAlchemy model-mapper-table. , Django SQLAlchemy.

, , save() Django, , SQL , SQLAlchemy , , SQLAlchemy , . Django, SQLAlchemy.

, .

, , , Django SQLAlchemy. . - django-transaction-hooks, , SQLAlchemy. , Django SQLAlchemy, after_commit.

, . SQLAlchemy - , Django .

+4

All Articles