[DB-SIG] SQL storage for Python objects

Greg Stein gstein@lyra.org
Wed, 02 Sep 1998 00:05:04 -0700


Joel Shprentz presented a paper at last year's conference on something
that is probably what you're looking for. It's online at:

http://www.python.org/workshops/1997-10/proceedings/shprentz.html

cheers,
-g

Patrick Curtain wrote:
> 
> Okay,
> 
> this is probably the most common question and might already be solved.
> OR, it might be one of those thorny things that noone really has a
> solution to.
> 
> Has anyone developed a useful idiom or pattern for storing python
> objects to relational databases?  Said another way, is there a
> well-defined API that improves on simply embedding all the SQL for the
> operations on an object?
> 
> So far, I'm simply including a method for each object that, given a key
> value, attempts to query the db (i'm using MySQL for now) for that
> object, populate the members and so on.  I provide the class with a
> write method, a read method and a delete method.
> 
> Another way to go about this, which i've also used, is to simply have a
> function that grabs all the data from the db using the fetchall method
> then iterates over the returned list of records and creates an object
> instance of that type using the record as the argument to __init__.
> 
> I'm getting the work done, i guess.  Just hoping that someone's thought
> through a better, more elegant way to go about it.  I suppose in some
> ways i'm also pining for an OpenSource alternative to
> GemStone/Smalltalk.  The object's storage was so intrinsic that you
> never had to think about it.  :)
> 
> Thanks for any help and ideas!
> --p

--
Greg Stein (gstein@lyra.org)                 execfile("disclaimer.py")