[storm] persistable members in a dict?
Tom Vaughan
tom at software6.net
Tue Sep 11 19:29:02 BST 2007
Hi,
As an example, I'd like to have a class that looks like:
class Channel(Persistable):
__storm_table__ = 'channel'
channelno = Int(primary=True)
__attrs__ = {
'frequency': {
'uom': 'GHz',
'value': Float(),
},
}
This is so I can attach metadata (like unit of measure is Hz or GHz)
to object members. And also so that I can have, for example, a toxml
method that would produce:
<channel><frequency uom="GHz">2.4</frequency></channel>
by easily iterating over __attrs__, and using the class name and the
'value' of the __attrs__ dict as special cases. And, if Persistable
above properly overrides __getattr__ and __setattr__, I can still do:
channel.frequency = 2.4
I know that I've hardcoded the metadata, and that the metadata won't
be stored in the database. I'm not worried about that now. And I
really don't want to subclass Int, Float, etc. for all the different
types of data I have and store each of these in their own table, etc.
I want something that (to me at least) is quick and simple, and a way
to collect all of the persistable members into one data structure. But
of course this breaks:
store.add(channel)
Hopefully this is clear. Can anyone think of a way I could do this?
Perhaps by extending Store?
Thanks.
-Tom
--
Website: www.software6.net
E-mail/Google Talk: tom (at) software6 (dot) net
Mobile: +1 (310) 704-0787
More information about the storm
mailing list