[Checkins] SVN: megrok.rdb/trunk/src/megrok/rdb/README.txt use engine created event to set up database.
Martijn Faassen
faassen at infrae.com
Fri Aug 15 16:50:20 EDT 2008
Log message for revision 89893:
use engine created event to set up database.
Changed:
U megrok.rdb/trunk/src/megrok/rdb/README.txt
-=-
Modified: megrok.rdb/trunk/src/megrok/rdb/README.txt
===================================================================
--- megrok.rdb/trunk/src/megrok/rdb/README.txt 2008-08-15 20:49:08 UTC (rev 89892)
+++ megrok.rdb/trunk/src/megrok/rdb/README.txt 2008-08-15 20:50:19 UTC (rev 89893)
@@ -98,8 +98,8 @@
First we grok this package's grokkers::
- >>> from grok.testing import grok
- >>> grok('megrok.rdb.meta')
+ >>> import grok.testing
+ >>> grok.testing.grok('megrok.rdb.meta')
Now we can grok the components::
@@ -147,11 +147,18 @@
>>> component.provideUtility(scoped_session, provides=IScopedSession)
-We now need to create the tables we defined in our database::
+Let's make sure that as soon as the engine is created, we create the
+appropriate metadata::
- >>> engine = engine_factory()
- >>> metadata.create_all(engine)
+We now need to create the tables we defined in our database. We can do this
+only when the engine is first created, so we set up a handler for it::
+ >>> from z3c.saconfig.interfaces import IEngineCreatedEvent
+ >>> @component.adapter(IEngineCreatedEvent)
+ ... def engine_created(event):
+ ... rdb.setupDatabase(metadata)
+ >>> component.provideHandler(engine_created)
+
Now all that is out the way, we can use the ``rdb.Session`` object to make
a connection to the database.
More information about the Checkins
mailing list