lanto03 / couchdb-python

Automatically exported from code.google.com/p/couchdb-python
Other
0 stars 0 forks source link

Providing different API for setting the limit option #134

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
How about adding the limit option to ViewResults? Adding it to the options 
dictionary does the trick, but it's ugly. We could have a trivial helper 
method, for example: 
https://code.google.com/r/grimborg-couchdb-python/source/detail?r=a51c08b088d520
21eb1e3415af27c7fb05b2859f

This would allow to write code like:

results = MyDocument.view(db, 'some/view').limit(10)

What do you think?

Thanks,

Òscar

Original issue reported on code.google.com by grimborg@gmail.com on 16 Jun 2010 at 9:19

GoogleCodeExporter commented 8 years ago
First off, I disagree that it's ugly. Also, I don't think special-casing some 
options is a good solution.

Original comment by djc.ochtman on 16 Jun 2010 at 10:50

GoogleCodeExporter commented 8 years ago
Well, we are already special-casing some options, namely key, startkey and 
endkey. It's common to use limit together with startkey.

Original comment by grimborg@gmail.com on 16 Jun 2010 at 11:33

GoogleCodeExporter commented 8 years ago
@grimborg are you referring to the ViewResult's __getitem__? If so, you're 
correct in that those options are special-cased although, now I've noticed that 
code, I'd be inclined to rip it out because it actually conflicts with the 
options passed to the view, i.e.

  db.view('_all_docs', startkey='a', endkey='b')['c':'d']

I would argue that a limit() method has exactly the same problem, i.e.

  db.view('_all_docs', limit=10).limit(5)

Personally, I also favour the simplicity of passing a limit=10 arg so I would 
-1 your suggestion. However, do you have a use case where a limit() method 
makes a significant difference to real code?

Original comment by matt.goo...@gmail.com on 16 Jun 2010 at 12:45

GoogleCodeExporter commented 8 years ago
You're absolutely right. I didn't see that the method args were sent as 
options. limit=10 is indeed nicer :)

Thanks!

Original comment by grimborg@gmail.com on 16 Jun 2010 at 1:37

GoogleCodeExporter commented 8 years ago

Original comment by matt.goo...@gmail.com on 16 Jun 2010 at 2:04