durusmail: quixote-users: zodb and scgi design question
zodb and scgi design question
2004-05-22
2004-05-24
2004-05-25
zodb and scgi design question
Titus Brown
2004-05-24
-> Moving along the quixote curve. I've succeeded in installing scgi on my
-> system, and qxdemo now whizzes along remarkably quickly! So, my next
-> step is to replace the pickling storage system with the zodb 3.2.1
-> backend. What I'm wondering is how to initialize the database
-> connection in the context of the scgi server (avoiding reinitializing
-> it everytime a URL is hit...) Right now, the __init__.py file at the
-> top of the qxdemo directory is empty, so I thought about putting the
-> zodb initializing stuff there, but I'm thinking that will be called
-> with every click, right? But I'm not sure where else to put it. It
-> seems as though it should be called when the scgi server is started.

[ munch ]

What I've been doing is putting it inside a separate library that's
imported by my application.  I usually break down my apps into

quixoteweb
quixotelib

where 'quixoteweb' is the exported Web site package and quixotelib
contains utility functions etc. that are used by the Web site package
and other scripts.  The desired separation becomes pretty obvious once
you have both a Web site and scripts to manipulate your database outside
of the Web site; anything that displays goes in the Web site, and
anything that manipulates the database directly goes in the external
lib.

So, I typically have a 'db' module that keeps a handle to the database
and gives it out via a 'get_conn' function.  For an example of this,
check out my SQL session persistence example code at

        http://issola.caltech.edu/~t/transfer/sql_example-13.4.04.tar.gz

Another approach would be to subclass the quixote.publish.Publisher
to have it store a database handle; then you can create the handle
at each SCGI server initialization, and access it by asking the
publisher object for it.

--titus


reply