On 7/12/06, Kevin Dangoor <[EMAIL PROTECTED]> wrote:
I'm writing a section about migrating a database from SQLObject to
SQLAlchemy. I think I've found a minor usability wart: in SQLObject,
you can do "SomeClass.select().count()". In SQLAlchemy with
ActiveMapper, the equivalent is "list( Page.table.count().execute())[0]
[0]", which is a little painful. (Straight up SQLAlchemy without
ActiveMapper still seems a bit cumbersome, because Page.table is just
replaced by "page" or whatever table instance you might have defined...)

Am I missing some shortcut, or is this really the way to do this?

I came accross the same problem.  I've added the following classmethod to the class from which all of my mapped classes inherit:

    @classmethod
    def count(cls, whereclause=None, **kwargs):
        return cls.mapper.table.count(whereclause, **kwargs).scalar()

table.count(where).scalar() isn't so bad, but I still prefer simply Class.count(where).  Maybe I'm missing something, too?

-David Shoemaker

Kevin


--
Kevin Dangoor
TurboGears / Zesty News

email: [EMAIL PROTECTED]
company: http://www.BlazingThings.com
blog: http://www.BlueSkyOnMars.com





-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users



--
--- I'd give my right arm to be ambidextrous. ---
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to