[Twisted-Python] SQL ORM for Twisted & PostgreSQL?

Burak Nehbit burak at nehbit.net
Wed Aug 21 12:15:24 MDT 2013


I am currently using SQLAlchemy with Twisted with deferToThread and it works rather well, have you tried it? So long as you create a new session for each thread you spawn (which you should also do without Twisted) it works without any modification required.

Here's an example of using SQLAlchemy with Twisted— no guarantees on it's the best way to do things, but it works.

def checkIfNodeExists(nodeId):
    def threadFunction():
        s = Session()
        r =  s.query(Node).filter(Node.NodeId == nodeId).count()
        if r is not 0:
            return True
        else:
            return False

    return threads.deferToThread(threadFunction)



On Aug 21, 2013, at 9:05 PM, Jonathan Vanasco <twisted-python at 2xlp.com> wrote:

> 
> It would be really beneficial if this were something that fully works with twisted, but is not dependent on it.
> 
> For example, I have a "Project" that mostly uses SqlAlchemy.  It started out in Pylons, new development is on Pyramid and there are additional tasks in Celery + some more in Twisted.  Aside from a few manual db tasks in Twisted, they all share and re-use a common "Model" package.  
> 
> Having a great ORM for twisted is wonderful , but its way less exciting and attractive if it's only for twisted.
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20130821/63b057ec/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4343 bytes
Desc: not available
URL: <http://twistedmatrix.com/pipermail/twisted-python/attachments/20130821/63b057ec/attachment.bin>


More information about the Twisted-Python mailing list