Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[soc2010/query-refactor] Implement a few methods to the point of test…
…s actually running under mongodb (all failing of course). git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13331 bcc190cf-cafb-0310-a4f2-bffc1f526a37
- Loading branch information
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,38 @@ | ||
from pymongo import Connection | ||
|
||
from django.db.backends import BaseDatabaseWrapper | ||
from django.db.backends.signals import connection_created | ||
from django.contrib.mongodb.creation import DatabaseCreation | ||
|
||
|
||
class DatabaseFeatures(object): | ||
interprets_empty_strings_as_nulls = False | ||
|
||
|
||
class DatabaseOperations(object): | ||
def max_name_length(self): | ||
return 254 | ||
|
||
def value_to_db_datetime(self, value): | ||
return value | ||
|
||
|
||
class DatabaseWrapper(BaseDatabaseWrapper): | ||
pass | ||
def __init__(self, *args, **kwargs): | ||
super(DatabaseWrapper, self).__init__(*args, **kwargs) | ||
self.features = DatabaseFeatures() | ||
self.ops = DatabaseOperations() | ||
self.creation = DatabaseCreation(self) | ||
self._connection = None | ||
|
||
@property | ||
def connection(self): | ||
if self._connection is None: | ||
self._connection = Connection(self.settings_dict["HOST"], | ||
self.settings_dict["PORT"] or None) | ||
connection_created.send(sender=self.__class__) | ||
return self._connection | ||
|
||
def _rollback(self): | ||
# TODO: ??? | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from django.db.backends.creation import TEST_DATABASE_PREFIX | ||
|
||
|
||
class DatabaseCreation(object): | ||
def __init__(self, connection): | ||
self.connection = connection | ||
|
||
def create_test_db(self, verbosity, autoclobber): | ||
if self.connection.settings_dict['TEST_NAME']: | ||
test_database_name = self.connection.settings_dict['TEST_NAME'] | ||
else: | ||
test_database_name = TEST_DATABASE_PREFIX + self.connection.settings_dict['NAME'] | ||
self.connection.settings_dict["NAME"] = test_database_name | ||
return test_database_name | ||
|
||
def destroy_test_db(self, old_database_name, verbosity=1): | ||
if verbosity >= 1: | ||
print "Destroying test database '%s'..." % self.connection.alias | ||
self.connection.connection.drop_database(self.connection.settings_dict["NAME"]) | ||
self.connection.settings_dict["NAME"] = old_database_name |