def DatabaseWrapper(*args, **kwargs): store_uri = get_store_uri(settings.DATABASE_NAME) # Create a DatabaseWrapper class that uses an underlying Storm # connection. We don't support sqlite here because Django expects # a bunch of special setup on the connection that Storm doesn't # do. if store_uri.startswith('postgres:'): global PostgresStormDatabaseWrapper if PostgresStormDatabaseWrapper is None: from django.db.backends.postgresql_psycopg2.base import ( DatabaseWrapper as PostgresDatabaseWrapper) class PostgresStormDatabaseWrapper(StormDatabaseWrapperMixin, PostgresDatabaseWrapper): pass DatabaseWrapper = PostgresStormDatabaseWrapper elif store_uri.startswith('mysql:'): global MySQLStormDatabaseWrapper if MySQLStormDatabaseWrapper is None: from django.db.backends.mysql.base import ( DatabaseWrapper as MySQLDatabaseWrapper) class MySQLStormDatabaseWrapper(StormDatabaseWrapperMixin, MySQLDatabaseWrapper): pass DatabaseWrapper = MySQLStormDatabaseWrapper else: assert False, ( "Unsupported database backend: %s" % store_uri) return DatabaseWrapper(*args, **kwargs)
def DatabaseWrapper(*args, **kwargs): store_uri = get_store_uri(settings.DATABASE_NAME) # Create a DatabaseWrapper class that uses an underlying Storm # connection. We don't support sqlite here because Django expects # a bunch of special setup on the connection that Storm doesn't # do. if store_uri.startswith('postgres:'): global PostgresStormDatabaseWrapper if PostgresStormDatabaseWrapper is None: from django.db.backends.postgresql_psycopg2.base import ( DatabaseWrapper as PostgresDatabaseWrapper) class PostgresStormDatabaseWrapper(StormDatabaseWrapperMixin, PostgresDatabaseWrapper): pass DatabaseWrapper = PostgresStormDatabaseWrapper elif store_uri.startswith('mysql:'): global MySQLStormDatabaseWrapper if MySQLStormDatabaseWrapper is None: from django.db.backends.mysql.base import (DatabaseWrapper as MySQLDatabaseWrapper) class MySQLStormDatabaseWrapper(StormDatabaseWrapperMixin, MySQLDatabaseWrapper): pass DatabaseWrapper = MySQLStormDatabaseWrapper else: assert False, ("Unsupported database backend: %s" % store_uri) return DatabaseWrapper(*args, **kwargs)
def test_get_store_uri(self): conf.settings.MIDDLEWARE_CLASSES += ( "storm.django.middleware.ZopeTransactionMiddleware",) conf.settings.STORM_STORES = {"name": "sqlite:"} self.assertEqual(stores.get_store_uri("name"), "sqlite:")