need convenient count() function at SQL and ORM level

Issue #26 resolved
Mike Bayer repo owner created an issue

On Dec 17, 2005, at 12:05 AM, limodou wrote:

If there is a count() method, just like:

number = count(user).execute()

or number = select(user).execute().count()

or somethins else

May be more helpful. So that you don't need to invoke fetchone() again.

I would vote for a "count" function on the base class for Selectable, which is any table, join, alias, select statement, union, etc.

so when you do:

x = mytable.count()

it compiles to:

x = select([count(1)](count(1)), from_obj=[mytable](mytable)).scalar()

when you do:

x = mytable.count(mytable.c.col1==7)

it compiles to:

x = select([count(1)](count(1)), mytable.c.col1==7).scalar()

the question is, do we want to put these functions at the ORM level as well:

x = User.mapper.count(User.c.user_name=='fred')

x = User.mapper.count_by(user_name='fred')

Comments (3)

  1. Mike Bayer reporter

    added table.count(<whereclause>).execute(<params>), fromobj.count(<whereclause>).execute(<params>), mapper.count(<whereclause>), mapper.count_by(<clauses>, <keyvalues>)

    798, 799

  2. Log in to comment