[storm] Testing the existance of values quickly

James Henstridge james at jamesh.id.au
Fri Sep 28 02:26:58 BST 2007


On 27/09/2007, Gustavo Niemeyer <gustavo at niemeyer.net> wrote:
>
> Hello,
>
> > How do I quickly test if there are results in the resultset?
>
> You can use bool(result.count()) or bool(result.any()).

It is also worth noting that in many cases it is cheaper to perform
one query than two, so the "check if the row exists, then retrieve it"
methodology is often slower.

Why not just request the row directly?

    user = store.find(User, User.username == u"Akira").one()
    if user is not None:
        ...

James.



More information about the storm mailing list