Created
May 16, 2016 20:33
-
-
Save tehasdf/87f159226c45c7ed8106262fe3d975be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ConnectionPool(txpostgres.ConnectionPool): | |
"""A txpostgres ConnectionPool that renders sqlalchemy queries | |
This is so you can pass a sqlalchemy Query object to .runQuery | |
and .runOperation. It will render it using the postgresql sqlalchemy | |
dialect. | |
""" | |
def __init__(self, **kwargs): | |
kwargs.setdefault('cursor_factory', NamedTupleCursor) | |
self._sqla_dialect = dialect() | |
super(ConnectionPool, self).__init__(None, **kwargs) | |
def runQuery(self, query, params=None): | |
query, params = getQueryWithParams(self._sqla_dialect, query, params) | |
return super(ConnectionPool, self).runQuery(query, params) | |
def runOperation(self, query, params=None): | |
query, params = getQueryWithParams(self._sqla_dialect, query, params) | |
return super(ConnectionPool, self).runOperation(query, params) | |
def start(self, *a, **kw): | |
started = Deferred() | |
def _waitForStart(): | |
return started | |
def _cbStarted(_): | |
started.callback(None) | |
return self | |
for i in range(self.min): | |
self._semaphore.run(_waitForStart) | |
return (super(ConnectionPool, self).start(*a, **kw) | |
.addCallback(_cbStarted)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment