[PEAK] ORM with the Trellis

Phillip J. Eby pje at telecommunity.com
Tue Feb 19 09:39:27 EST 2008

At 04:25 PM 2/19/2008 +0200, niki wrote:
>Phillip J. Eby wrote:
>>At 11:44 AM 2/19/2008 +0200, niki wrote:
>>>Does this mean than one can define rule dependent on some record 
>>>source and lazy track changes on that source?
>>I'm not sure what you mean.  But here's what I meant: if you have a 
>>set of records that offers 'added' and 'removed' event sets (the 
>>way a trellis.Set does), then you can certainly have rules that 
>>depend on those events.
>>How those records get into the record set or the added/removed sets 
>>is of course a separate question.
>I would like record set and rule to live in external SQL storage and 
>lazily reevaluate if 'added' or 'removed' events were fired after 
>last calculation. Something like external persistence of dependency graph.
>   invoice.total = LazyRule(sum(item.value for item in invoice.item_set))
>where invoice and item are SQL persistent records and total is 
>calculated on request only if item_set changed after last calculation.
>If only item_set can have it's own persistent pulse counter which is 
>updated by 'added' and 'removed' events.

You can do that, but it would look more like:

    for item in invoice.item_set.removed:
        total -= item.value
    for item in invoice.item_set.added:
        total += item.value

It's also not clear to me if you're talking about one process 
controlling an SQL backend, or whether you want processes to pick up 
changes made by other processes.  The latter would require some other 
communication mechanism, such as polling the DB or using something 
like Spread to broadcast changes.

More information about the PEAK mailing list