Hi: I'm jumping into this discussion cause I'm also doing something similar.. On Wed, 26 May 1999, Martijn Faassen wrote:
How do you plan to use Python to talk to databases? Are you going to use Zope or use the Python db-api? If you use Zope SQL methods you need to talk through these methods from your Python. I don't have experience with it but this is possible; the Z SQL methods can be treated as Python methods from Python, basically.
Using Zope's SQL methods work pretty well. When you call the SQL method from Python it returns an instance of the Results class (see Shared/DC/ZRDB in the lib dir). Its actually really easy to use this class because it has overridden indexing methods, etc, so you can do something like: rs = sql_method() rcpts = map(lambda x: x['email'], rs) (note there is a bit of trickiness involved getting the method. Sometimes I pass it as a parameter from a DTML #call tag) So this extracts the email column from each row and puts it into a list. Obviously the main advantage here is that you can abstract the database layer. I suppose this means you don't even need to access SQL databases, since other things could return Results objects. Fun stuff. :)
Another tricky part would be 'business objects'. The simple way to interface Zope with Python are external methods (written in Python). If you get your business objects done with external methods, I'd recommend this route. External methods are not 'business objects', however ('business methods', I suppose?), though of course you can package a number of them together inside a Zope folder. (you can bundle them in a subfolder which will be automatically acquired by other subfolders..this way they remain manageable and don't pollute your root folder).
One idea I was playing around was using the pluggable brains support with SQL methods to wrap all results into business objects. I haven't really found much documentation on this, but I will be investigating this very soon as I prototype some stuff to explore various implementation methods. What do you think about this instead of external methods? Managing a class is sometimes easier than managing a bunch of seperate methods.
Another way in the future would be to use ZClasses. ZClasses are part of the Zope 2.0 Alpha, but it'll take some time before there'll be a production version of Zope featuring them. From what I understand of ZClasses you can create a new Zope product from inside Zope with them (basically by packaging DTML and external methods together).
Hmm, I am wondering about using ZClasses because I'd like to further abstract data storage by saying that I could either store objects in the ZODB or in a SQL database. One thing missing to fully enable this are ZODB Query Methods which would allow you to return Results objects from a ZODB-based query. Maybe this already exists for ZTables? If so I'd like to know. Does this mean a ZClass could potentially be used as a pluggable brain for SQL Method or are we talking different things here. Anyway, that's enough for me. my brain hurts. :) ------- Jordan B. Baker -- jbb@spyderlab.com weaving the web @ http://www.spyderlab.com