[Tutor] storing dict objects in in a database through SQLObject

Kent Johnson kent37 at tds.net
Mon Jul 3 18:56:20 CEST 2006


Emily Fortuna wrote:
>  > The question is one of balance: are you more concerned with
>  > easily getting your dicts and tuples back intact, or with executing
>  > queries on the *contents* of those dicts and tuples?
> Ideally, I'd like to be able to search the data in these dicts.  Is 
> there a way to do this? If not, PickleCol seems to be the way to go...
> 
> To Kent:
>  > What is in the dicts and tuples?
> I am trying to store several different classes of objects into the 
> database using SQLObject, some of which have dicts as attributes.  The 
> classes may be extended and the dicts store variable amounts of entries. 
>   I want this framework to be extensible as possible, but perhaps I am 
> taking the wrong approach.  The object classes were designed with their 
> manipulation in mind, in addition to simply database storage. Is there a 
> better design you can suggest?

The objects have a one-to-many relationship with the attributes. Maybe 
you should have a class to hold an attribute and set up a one-to-many 
relationship in SQLObject. Then the main object would contain a list of 
attributes, rather than a dict.

As far as I know SQLObject doesn't support a named mapping in the style 
of a dict. But I am just a dabbler in SQLObject; you might want to ask 
on the SQLObject mailing list.

SQLAlchemy seems to support what you want; see this example:
http://www.sqlalchemy.org/docs/adv_datamapping.myt#advdatamapping_properties_customlist

Another alternative is an object database such as ZODB or Durus.

Kent



More information about the Tutor mailing list