[PEAK] peak.model and mappings?
Bob Ippolito
bob at redivi.com
Tue Feb 24 03:42:33 EST 2004
On Feb 23, 2004, at 8:35 PM, Bob Ippolito wrote:
> On Feb 23, 2004, at 8:12 AM, Phillip J. Eby wrote:
>
>> At 08:35 PM 2/22/04 -0500, Bob Ippolito wrote:
>>> How are you supposed to define a mapping with peak.model? I'm
>>> looking for something that would be used like this, in theory:
>>>
>>> from peak.api import *
>>>
>>> class MyElement(model.Element):
>>>
>>> class elementToStringMapping(model.Mapping):
>>> referencedKeyType = 'MyElement'
>>> referencedType = model.String
>>
>> There isn't such a feature type at present, I'm afraid. But if you
>> look at peak.metamodels.MOF131.Namespace, you'll see an
>> implementation of an "indexed" relationship whereby a sequence of
>> objects is also indexed in a mapping. It's not quite the same thing,
>> but for some applications it's actually better, since it also retains
>> sequence information. If your value objects don't reference their
>> keys, use a tuple as the target type. IOW, if your feature's
>> singular name is 'mapping':
>>
>> anElement.addMapping((key,value))
>>
>> would add the key-value pair. You can define additional verbs of
>> course that do this in a cleaner-seeming way, according to your app's
>> needs.
>>
>> Or you can completely override the standard stuff and do it your own
>> way altogether.
>
> Ah I see. Basically, what I was trying to do was more of a metamodel,
> like building tables in SQL (not triggers, stored procedures, etc)..
> model the data, not its behavior, so I wanted to put as much metadata
> in there as possible. I think I will try and develop my own
> "model.Mapping" to go along with this style, because I don't want to
> tie myself to python dicts, or ZODB BTrees, or what have you, and I do
> need to know what kind of objects are used for keys, and what for
> values.
>
> Basically, I want to define the specification and decide what the
> implementation is going to be later, or even use the specs to
> implement a storage for me (i.e. design SQL tables based upon my
> Element classes and their StructuralFeatures).
Here is my first pass at extending StructuralFeature and friends to
support mappings...
It would be great if someone (PJE, preferably) could take a look at it
and let me know if I'm going in the right direction here.. I'm still
new to PEAK :)
-bob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: model_support.py
Type: application/octet-stream
Size: 9164 bytes
Desc: not available
Url : http://www.eby-sarna.com/pipermail/peak/attachments/20040224/4654fd5c/model_support.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_model_support.py
Type: application/octet-stream
Size: 1322 bytes
Desc: not available
Url : http://www.eby-sarna.com/pipermail/peak/attachments/20040224/4654fd5c/test_model_support.obj
More information about the PEAK
mailing list