Added SwitchDB context manager (#106)

This commit is contained in:
Ross Lawley
2013-01-23 12:54:14 +00:00
parent 6d68ad735c
commit e5e88d792e
5 changed files with 85 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ Connecting
.. autofunction:: mongoengine.connect
.. autofunction:: mongoengine.register_connection
.. autoclass:: mongoengine.SwitchDB
Documents
=========

View File

@@ -32,6 +32,7 @@ Changes in 0.8.X
- Fixed inheritance and unique index creation (#140)
- Fixed reverse delete rule with inheritance (#197)
- Fixed validation for GenericReferences which havent been dereferenced
- Added SwitchDB context manager (#106)
Changes in 0.7.9
================

View File

@@ -69,3 +69,21 @@ to point across databases and collections. Below is an example schema, using
book = ReferenceField(Book)
meta = {"db_alias": "users-books-db"}
Switch Database Context Manager
===============================
Sometimes you might want to switch the database to query against for a class.
The SwitchDB context manager allows you to change the database alias for a
class eg ::
from mongoengine import SwitchDB
class User(Document):
name = StringField()
meta = {"db_alias": "user-db"}
with SwitchDB(User, 'archive-user-db') as User:
User(name="Ross").save() # Saves the 'archive-user-db'