[Cubicweb] Proposal: new method ResultSet.one()

afayolle afayolle.ml at free.fr
Thu Dec 5 14:34:56 CET 2013


On 04/12/2013 15:40, Christophe de Vienne wrote:
> Hi,
>
> I propose to add a new method to ResultSet, named one(), that would
> return exactly one entity from the resultset.
> If more than one row and one column, or no row at all is found, an
> exception would be raised.
>
> It would allow to write :
>
> entity = execute('SOME REQUEST').one()
>
> where right now we have to do :
>
> rset = execute('SOME REQUEST')
> if rset.rowcount != 1:
>     # do something
> entity = rset.get_entity(0, 0)
>
> The idea is shamelessly borowed from SQLAlchemy Query.one() [1]
>
> I have a patch that propose an implementation, I can push it for review
> and discussion if you think it is worth it.
>
> Christophe
>
> PS: btw, I did not manage to run the cubicweb test suite, is there some
> things to be known to do so ?
>
> [1]
> http://docs.sqlalchemy.org/en/rel_0_9/orm/query.html#sqlalchemy.orm.query.Query.one
> _______________________________________________
> Cubicweb mailing list
> Cubicweb at lists.cubicweb.org
> http://lists.cubicweb.org/mailman/listinfo/cubicweb
Would this be significantly different from calling next() on the rset ?

-- 
Alexandre



More information about the Cubicweb mailing list