you'd need to patch some kind of fake DBAPI connection that returns this cursor from the cursor() method. it would be ugly but if the cursor behaves well it could work. you'd get session.connection() to get a sqlalchemy.engine.Connection, then patch your "fake" DBAPI connection into it as the underlying connection object. (or use a pool with custom "creator" + engine).

On 03/22/2017 03:54 PM, Jonathan Vanasco wrote:
longshot, i know.

We've got some legacy twisted code that does raw operations via a
twisted.enterprise.adbapi connection pool with the psycopg2 driver.
 Other services in this deployment are configured to use SqlAlchemy for
all operations - this is the legacy holdout.

There are a few chunks of blocking code that have a performance
bottleneck caused by multiple updates to the same records.

I'm wondering if it's possible to leverage the orm on top of this
existing connection's cursor.  The basic idea would be this:

   s = Session(connection=twisted_dbapi_cursor)
   foo = s.query(Foo).get()
   s.flush()
   txn.commit()
   s.close()

I've seen stuff about using an engine build off an existing connection,
but I only have the cursor - not the connection itself.  The connection
is a private attribute in the cursor, so i could potentially access
it.... but that could cause issues that scare me at this point.

--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and
Verifiable Example. See http://stackoverflow.com/help/mcve for a full
description.
---
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to