Thanks, I actaully managed to find the paginator first time. It even
led me to similar one in ROR.

I guess I'm gonna stick with this lib even if it isn't what I was
looking for. I was looking for a way for SQLAlchemy to defer it's
execution, but since there is no such a way, I'm going for the closest
thing.

It might seem like nitpicking, but I was trying to convert functions
like this one:

    def get_stranke(self, limit=None, offset=None, min_tezina=None):
        K, S, SI = CCKampanja, CCStranka, CCStrankaImenik
        where = and_(S.c.kampanja_id==self.id)
        if min_tezina:
            where.append(
                exists([SI.c.stranka_id],
                    and_(SI.c.stranka_id==S.c.id, SI.c.tezina>=min_tezina)))
        total = select([func.count(S.c.id)], where).execute().fetchone()[0]
        rows = S.select(where, order_by=S.c.pozicija, limit=limit,
offset=offset)
        return rows, total

Into something like this:

    # avoid using limit/offset and unnecessary count
    def get_stranke(self, min_tezina=None):
        K, S, SI = CCKampanja, CCStranka, CCStrankaImenik
        where = and_(S.c.kampanja_id==self.id)
        if min_tezina:
            where.append(
                exists([SI.c.stranka_id],
                    and_(SI.c.stranka_id==S.c.id, SI.c.tezina>=min_tezina)))
        return S.defered_select(where, order_by=S.c.pozicija)

So I can later say this inside my controller1:

    # avoid unnecessary fetches because limit/offset is implicitly used
    paginator, items = paginate(camp.get_stranke(min_tezina), ...)

or say this inside my controller2:

    # avoid count
    for s in camp.get_stranke(min_tezina):
        # ... process every element ...

My idea is to program like there is no limit/offset and to apply
limit/offset only in those places where it is aplicable and still have
efficient database access.

Regards,
Tvrtko

On 3/23/06, Todd Grimason <[EMAIL PROTECTED]> wrote:
> * Michael Bayer [2006-03-22 16:38]:
> > mapper.select() takes a limit and offset parameter:
> >
> > http://www.sqlalchemy.org/docs/
> > adv_datamapping.myt#adv_datamapping_limits
> >
> > also Ben Bangert I think has some widget hes using with Pylons that
> > does this same thing with SQLAlchemy in a configurable way.
>
> You might just be able to grab this lib if you need pagination:
>
> http://www.pylonshq.com/project/pylonshq/browser/WebHelpers/trunk/webhelpers/pagination/
>
> It's used in lib/generics.py: View.list()
>
> http://groups.google.com/group/pylons-discuss/msg/3a174f5f1ae968b2
>
> in the attachment to the above link/post.
>
>
>
> --
>
> ________________________________
> toddgrimason*todd[ at ]slack.net
>
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting language
> that extends applications into web and mobile media. Attend the live webcast
> and join the prime developer group breaking into this new coding territory!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
> _______________________________________________
> Sqlalchemy-users mailing list
> Sqlalchemy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users
>


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to