Michael Bayer wrote:
> i wonder though if theres some way that could get "out of sync" with  
> the actual number.  you'd have to be careful to establish this  
> update.  if you wanted to use a mapper extension to do it, then youd  
> have to issue the UPDATE directly, the change to the "comment_count"  
> attribute wont get picked up if its established within the flush itself.

Hi,

Thank you Michael for help, and for new great docs!

I've finally done first POC implementation of this feature.

Basic usage looks like:

import aggregator as a
mapper(Line, lines,
     extension=a.Quick(a.Count(blocks.c.lines),
        a.Max(blocks.c.lastline, lines.c.id)))

(You also need foreign keys)

I've implemented two interfaces one
that counts like "cnt = cnt+1" (called Quick)
second does query "SELECT count(*) FROM ...."
at each insert/update/delete (called Accurate)

Well, Quick should be accurate as long as you either don't
update foreign keys involved in process, or have only one
Count aggregation on changable key (*), or use transactions.
So it covers most usecases I think. If you like to recalc you can
use Accurate which can be better in some edge cases.
A bit slower on updates but still fast on reads.

(*) - aggregations on update is not implemented yet, but it's
only a matter of time

For more comprehensive description look here:
http://www.mr-pc.kiev.ua/projects/SQLAlchemyAggregation

I have also two issues.

1. func.if_(...) - tries to sql function "if_(...)",
but func._if(...) - "_i(...)"
I believe is typo?

2.  If there a way, to handle functions in cross-database manner?

I've need to write something like this, for max function which
exists on sqlite but absent in mysql (and if() visa-versa):

        if aggregator.mapper.local_table.\
                metadata.bind.url.drivername == 'mysql':
            return if_func(A < B, B, A)
        else:
            return func.max(A, B)

Is there a better way?
(Well, I will decrease number of dots it no better way exists :) )

--
Paul.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to