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

Christophe de Vienne cdevienne at gmail.com
Thu Dec 5 16:07:46 CET 2013


The difference is that next will not enforce that only one entity is returned by the query.


afayolle <afayolle.ml at free.fr> a écrit :
>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
>_______________________________________________
>Cubicweb mailing list
>Cubicweb at lists.cubicweb.org
>http://lists.cubicweb.org/mailman/listinfo/cubicweb

-- 
Envoyé de mon téléphone Android avec K-9 Mail. Excusez la brièveté.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cubicweb.org/pipermail/cubicweb/attachments/20131205/d5d3d2d6/attachment-0127.html>


More information about the Cubicweb mailing list