if you want all the SQLObject functions on results, you can use the  
SelectResults plugin which is based on that of SQLObject:

        http://www.sqlalchemy.org/docs/plugins.myt#plugins_selectresults

(should probably have a flag on ActiveMapper to turn SelectResults on  
individual classes....)

but also, the Query object contains count() and count_by():

        session.query(MyClass).count(MyClass.c.foo=='bar')

the assignmapper plugin, which is whats giving you "SomeClass.select 
()" in the first place, is just proxying methods off to a Query  
object, so I just added "count()" and "count_by()" to the list of  
proxied methods in rev 1705, so you can just  do:

        MyClass.count(<optional criterion>)

the full list of things that are proxied by assignmapper can be seen  
on lines 34 and 36 of sqlalchemy/ext/assignmapper.py .



On Jul 12, 2006, at 10:29 PM, Kevin Dangoor 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?
>
> 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



-------------------------------------------------------------------------
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