[storm] Storm and database pooling

Stanko Petrovic stanep at gmail.com
Tue Aug 21 13:52:54 BST 2007


I try to implement database pooling with Storm using sqlalchemy pooling and
it seems it works.

Something like this

import pyodbc
import sqlalchemy.pool as pool
from storm.locals import *
pool = pool.manage(pyodbc,echo=True)


store=Store(create_database("mssql://:@N5010/Dummy",pool))


in database.py  in create_database function I added this code



def create_database(uri,pool=None):
    """Create a database instance.

    @param uri: An URI instance, or a string describing the URI. Some
examples:
        "sqlite:" An in memory sqlite database.
        "sqlite:example.db" A SQLite database called example.db
        "postgres:test" The database 'test' from the local postgres server.
        "postgres://user:password@host/test" The database test on machine
host
            with supplied user credentials, using postgres.
        "anything:..." Where 'anything' has previously been registered
            with L{register_scheme}.
    """
    if isinstance(uri, basestring):
        uri = URI(uri)
    if uri.scheme in _database_schemes:
        factory = _database_schemes[uri.scheme]
    else:
        module = __import__("%s.databases.%s" % (storm.__name__, uri.scheme
),
                            None, None, [""])
        if pool:
            module.create_from_uri.pyodbc_pool=pool
        factory = module.create_from_uri
    return factory(uri)







and in my /database/mssql.py class I use





class Mssql(Database):

    _connection_factory = MssqlConnection


    def __init__(self, uri):
        if pyodbc is dummy:
            raise DatabaseModuleError("'pyodbc' module not found")
        self._dsn = make_dsn(uri)
        #self.pool = pool.manage(pyodbc,echo=True)


    def connect(self):

        raw_connection = Mssql.pyodbc_pool.connect(self._dsn)
        raw_connection.execute('SET nocount ON')
        return self._connection_factory(self, raw_connection)


create_from_uri = Mssql







I am trying to get pyodbc work with MSSql (it works kind of) but this
technic could be applied to other db backends.

Tell me what you guys think
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ubuntu.com/archives/storm/attachments/20070821/f99feba9/attachment.htm 


More information about the storm mailing list