Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLAlchemy and django, is it production ready?

Tags:

Has anyone used SQLAlchemy in addition to Django's ORM?

I'd like to use Django's ORM for object manipulation and SQLalchemy for complex queries (like those that require left outer joins).

Is it possible?

Note: I'm aware about django-sqlalchemy but the project doesn't seem to be production ready.

like image 251
Piotr Czapla Avatar asked Jul 20 '09 15:07

Piotr Czapla


People also ask

Is SQLAlchemy production ready?

It's doable, of course.

Can SQLAlchemy be used with Django?

Both Django and SQLAlchemy can be used with MySQL, PostgreSQL, Oracle and SQLite. If you're using MSSQL, you should go for SQLAlchemy, as it's fully supported by it and you'll find more information and documentation about it.

Is it worth using SQLAlchemy?

SQLAlchemy is great because it provides a good connection / pooling infrastructure; a good Pythonic query building infrastructure; and then a good ORM infrastructure that is capable of complex queries and mappings (as well as some pretty stone-simple ones).

Does SQLAlchemy support batching?

SQLAlchemy supports the widest variety of database and architectural designs as is reasonably possible. Unit Of Work. The Unit Of Work system, a central part of SQLAlchemy's Object Relational Mapper (ORM), organizes pending insert/update/delete operations into queues and flushes them all in one batch.


2 Answers

What I would do,

  1. Define the schema in Django orm, let it write the db via syncdb. You get the admin interface.

  2. In view1 you need a complex join

      def view1(request):        import sqlalchemy        data = sqlalchemy.complex_join_magic(...)        ...        payload = {'data': data, ...}        return render_to_response('template', payload, ...)  
like image 193
agiliq Avatar answered Oct 24 '22 02:10

agiliq


I don't think it's good practice to use both. You should either:

  1. Use Django's ORM and use custom SQL where Django's built-in SQL generation doesn't meet your needs, or
  2. Use SQLAlchemy (which gives you finer control at the price of added complexity) and, if needed, use a declarative layer such as Elixir to make life a little easier.

Of course, if you need Django's admin, then the first of these approaches is recommended.

like image 23
Vinay Sajip Avatar answered Oct 24 '22 01:10

Vinay Sajip