mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1681 bcc190cf-cafb-0310-a4f2-bffc1f526a37
30 lines
1.3 KiB
Python
30 lines
1.3 KiB
Python
from django.conf.settings import DATABASE_ENGINE
|
|
|
|
__all__ = ('backend', 'connection', 'DatabaseError')
|
|
|
|
if not DATABASE_ENGINE:
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
raise ImproperlyConfigured, "You haven't set the DATABASE_ENGINE setting yet."
|
|
|
|
try:
|
|
backend = __import__('django.db.backends.%s.base' % DATABASE_ENGINE, '', '', [''])
|
|
except ImportError, e:
|
|
# The database backend wasn't found. Display a helpful error message
|
|
# listing all possible database backends.
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
import os
|
|
backend_dir = os.path.join(__path__[0], 'backends')
|
|
available_backends = [f for f in os.listdir(backend_dir) if not f.startswith('_') and not f.startswith('.')]
|
|
available_backends.sort()
|
|
raise ImproperlyConfigured, "Could not load database backend: %s. Is your DATABASE_ENGINE setting (currently, %r) spelled correctly? Available options are: %s" % \
|
|
(e, DATABASE_ENGINE, ", ".join(map(repr, available_backends)))
|
|
|
|
def get_introspection_module():
|
|
return __import__('django.db.backends.%s.introspection' % DATABASE_ENGINE, '', '', [''])
|
|
|
|
def get_creation_module():
|
|
return __import__('django.db.backends.%s.creation' % DATABASE_ENGINE, '', '', [''])
|
|
|
|
connection = backend.DatabaseWrapper()
|
|
DatabaseError = backend.DatabaseError
|