<div>I try to implement database pooling with Storm using sqlalchemy pooling and it seems it works.</div>
<div> </div>
<div>Something like this</div>
<div> </div>
<div>import pyodbc<br>import sqlalchemy.pool as pool<br>from storm.locals import *<br>pool = pool.manage(pyodbc,echo=True)</div>
<div> </div>
<div> </div>
<div>store=Store(create_database("mssql://:@N5010/Dummy",pool))</div>
<div> </div>
<div> </div>
<div>in database.py in create_database function I added this code</div>
<div> </div>
<div> </div>
<div>
<p>def create_database(uri,pool=None):<br> """Create a database instance.</p>
<p> @param uri: An URI instance, or a string describing the URI. Some examples:<br> "sqlite:" An in memory sqlite database.<br> "sqlite:example.db" A SQLite database called example.db
<br> "postgres:test" The database 'test' from the local postgres server.<br> "postgres://user:password@host/test" The database test on machine host<br> with supplied user credentials, using postgres.
<br> "anything:..." Where 'anything' has previously been registered<br> with L{register_scheme}.<br> """<br> if isinstance(uri, basestring):<br> uri = URI(uri)
<br> if uri.scheme in _database_schemes:<br> factory = _database_schemes[uri.scheme]<br> else:<br> module = __import__("%s.databases.%s" % (storm.__name__, uri.scheme),<br> None, None, [""])
<br> if pool:<br> module.create_from_uri.pyodbc_pool=pool<br> factory = module.create_from_uri<br> return factory(uri)</p>
<p> </p>
<p> </p>
<p> </p>
<p>and in my /database/mssql.py class I use </p>
<p> </p>
<p> </p>
<p>class Mssql(Database):</p>
<p> _connection_factory = MssqlConnection</p>
<p> <br> def __init__(self, uri):<br> if pyodbc is dummy:<br> raise DatabaseModuleError("'pyodbc' module not found")<br> self._dsn = make_dsn(uri)<br> #self.pool =
pool.manage(pyodbc,echo=True)</p>
<p><br> def connect(self):<br> <br> raw_connection = Mssql.pyodbc_pool.connect(self._dsn)<br> raw_connection.execute('SET nocount ON')<br> return self._connection_factory(self, raw_connection)
</p>
<p><br>create_from_uri = Mssql</p>
<p> </p>
<p> </p>
<p> </p>
<p>I am trying to get pyodbc work with MSSql (it works kind of) but this technic could be applied to other db backends.</p>
<p>Tell me what you guys think</p>
<p> </p></div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div> </div>