summaryrefslogtreecommitdiff
path: root/django/db/backends/__init__.py
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2009-03-11 03:39:34 +0000
committerAdrian Holovaty <adrian@holovaty.com>2009-03-11 03:39:34 +0000
commit315145f7ca682f8361d956e985f533a7fb421cde (patch)
tree959f7bac4d8356e4b900227646eace9f7c05ab48 /django/db/backends/__init__.py
parent7daf0b94070ab29419825156ec68bca813e3c09f (diff)
Fixed #10459 -- Refactored the internals of database connection objects so that connections know their own settings and pass around settings as dictionaries instead of passing around the Django settings module itself. This will make it easier for multiple database support. Thanks to Alex Gaynor for the initial patch.
This is backwards-compatible but will likely break third-party database backends. Specific API changes are: * BaseDatabaseWrapper.__init__() now takes a settings_dict instead of a settings module. It's called settings_dict to disambiguate, and for easy grepability. This should be a dictionary containing DATABASE_NAME, etc. * BaseDatabaseWrapper has a settings_dict attribute instead of an options attribute. BaseDatabaseWrapper.options is now BaseDatabaseWrapper['DATABASE_OPTIONS'] * BaseDatabaseWrapper._cursor() no longer takes a settings argument. * BaseDatabaseClient.__init__() now takes a connection argument (a DatabaseWrapper instance) instead of no arguments. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10026 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/backends/__init__.py')
-rw-r--r--django/db/backends/__init__.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py
index 187ff6cfe6..6ca7b87116 100644
--- a/django/db/backends/__init__.py
+++ b/django/db/backends/__init__.py
@@ -24,10 +24,14 @@ class BaseDatabaseWrapper(local):
Represents a database connection.
"""
ops = None
- def __init__(self, **kwargs):
+ def __init__(self, settings_dict):
+ # `settings_dict` should be a dictionary containing keys such as
+ # DATABASE_NAME, DATABASE_USER, etc. It's called `settings_dict`
+ # instead of `settings` to disambiguate it from Django settings
+ # modules.
self.connection = None
self.queries = []
- self.options = kwargs
+ self.settings_dict = settings_dict
def _commit(self):
if self.connection is not None:
@@ -59,7 +63,7 @@ class BaseDatabaseWrapper(local):
def cursor(self):
from django.conf import settings
- cursor = self._cursor(settings)
+ cursor = self._cursor()
if settings.DEBUG:
return self.make_debug_cursor(cursor)
return cursor
@@ -498,6 +502,10 @@ class BaseDatabaseClient(object):
# (e.g., "psql"). Subclasses must override this.
executable_name = None
+ def __init__(self, connection):
+ # connection is an instance of BaseDatabaseWrapper.
+ self.connection = connection
+
def runshell(self):
raise NotImplementedError()