9

I have two apps that both access the same database. The first has clients connecting via TCP and writes to the db using SQLAlchemy. The second is a more typical webapp using Django. Both have read/write requirements.

I would like to unify the database access layer, but picking just SQLAlchemy or just Django is unattractive because:

  1. I would like to use django auth, permissions, and maybe third party plugins, which require the Django ORM (correct me if I'm wrong).
  2. For the first app, using SQLAlchemy (so far) is much simpler than trying to use the Django ORM outside of a Django app - it is a TCP/IP server app, not a HTTP/web app.

Are there any problems with mixing these two ORMs on the same database?

In which system (Django, SQLA) should I create the models, vs using some kind of introspection such as Django inspectdb?

user1431368
  • 585
  • 8
  • 15
  • I have just found [django-sqlalchemy](https://code.google.com/p/django-sqlalchemy/wiki/Roadmap) project. I don't know if it suits to your needs, but it is definitely worth of reading about it. – noisy Jul 02 '13 at 14:32

1 Answers1

8

Firstly - it's not very hard to use Django ORM outside a manage.py, WSGI handlers and other HTTP related stuff. You can use it any python script, but it needs some initialization (example).

Secondly - SQLA is a very powerfull tool and it's able to do stuff which is very hard to achive in Django ORM (like genuine polymorphism and polymorphic queries). If I had to choose, I'd personally choose to use Django ORM as a platform to create models, then manually map them in SQLA since it is much more flexibile and hopefully will be able to adopt. Which may not work in the opposite case.

Finally, since you can use Django ORM on both sides, and you just have to use a Django ORM because of the plugins, I suggest to abandon the SQLA. It's a powerfull tool, but also rather complicated. Having two different ORMs operating on one database may result in unexpected problems in the future and increases the complexity of your app, so it'll be harder to maintenance.

Community
  • 1
  • 1