I am trying to share connection between Django and SqlAlchemy. I tried
following code:
from django.db import connection
from sqlalchemy import create_engine
def get_connection():
if connection.connection is None:
connection._cursor() # TODO: better way to open new
connection?
return connection.connection
engine = create_engine('postgresql+psycopg2://',
creator=get_connection)
engine.execute(s) # s - SqlAlchemy query
But this results in various fails in SqlAchemy (like connection is
already closed, can't execute some queries). More details are
available here:
http://stackoverflow.com/questions/6439119/django-and-sqlalchemy-share-connection
So I have following question:
- does anyone know working solution?
- how big will be performance impact if I use separate connection for
Django and SqlAlchemy?
- any explanations why current code is not working :)
Thanks.