You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Holger Krekel <ho...@gmail.com> on 2012/12/13 15:59:45 UTC
writing show/list functions in python
Besides view functions, is it possible to write show/list functions in
python?
I saw and old issue and patch about this at
http://code.google.com/p/couchdb-python/issues/detail?id=78
But not anything in the docs. If it's not available is this planned?
Re: writing show/list functions in python
Posted by Alexander Shorin <kx...@gmail.com>.
For object-like design document definition, see issue 186:
http://code.google.com/p/couchdb-python/issues/detail?id=186
and here we go:
class MyDDoc(Document):
@ViewFunction.map('foo')
def by_bar(doc):
for bar in doc['foo']:
yield bar, None
by_bar.reduce('_count') # use built-in reduce
@ShowFunction.define('foo')
def bar(doc, req):
return {'json': doc['foo']}
@ValidateDocUpdateFunction.define('foo')
def vdu(newdoc, olddoc, userctx, secobj):
assert 'foo' in newdoc, 'foo missed'
sync_docs(db, [MyDDoc]) # creates and stores _design/foo ddoc
But it will be useless without query server that support of all these functions.
--
,,,^..^,,,
On Fri, Dec 14, 2012 at 2:31 AM, Holger Krekel <ho...@gmail.com> wrote:
> Thanks for the info, Alexander.
>
> On a sidenote, instead of deep directory structures, i am using this style
> of declaring my map/reduce functions in Python:
>
> @couch.view("access")
> class packagenames:
> @staticmethod
> def map(doc):
> return doc["_id"]
> @staticmethod
> def reduce(keys, values, rereduce):
> return 1
>
> The decorator just sets an attribute and returns the unmodified class.
> Later i scan the module, do a little bit of introspection and push the
> functions to _design/access/_view/packagenames. The @staticmethod is
> purely there to allow easy testing (just call packagenames.map(doc) etc. on
> an example doc. If there is interest, i can see to release that code
> sometime.
>
> cheers,
> holger
> --
> http://holgerkrekel.net
>
>
>
> On Thu, Dec 13, 2012 at 6:24 PM, Alexander Shorin <kx...@gmail.com> wrote:
>
>> Hi Holger!
>>
>> Take a look on:
>> http://code.google.com/p/couchdb-python/issues/detail?id=146
>> it contains up-to-dated query server with support of all design
>> function in Python. With latest patch you'll find short rst guide
>> about how to start writing Python ddocs and what their differences
>> from Javascript ones.
>> --
>> ,,,^..^,,,
>>
>>
>> On Thu, Dec 13, 2012 at 6:59 PM, Holger Krekel <ho...@gmail.com>
>> wrote:
>> > Besides view functions, is it possible to write show/list functions in
>> > python?
>> >
>> > I saw and old issue and patch about this at
>> > http://code.google.com/p/couchdb-python/issues/detail?id=78
>> >
>> > But not anything in the docs. If it's not available is this planned?
>>
Re: writing show/list functions in python
Posted by Holger Krekel <ho...@gmail.com>.
Thanks for the info, Alexander.
On a sidenote, instead of deep directory structures, i am using this style
of declaring my map/reduce functions in Python:
@couch.view("access")
class packagenames:
@staticmethod
def map(doc):
return doc["_id"]
@staticmethod
def reduce(keys, values, rereduce):
return 1
The decorator just sets an attribute and returns the unmodified class.
Later i scan the module, do a little bit of introspection and push the
functions to _design/access/_view/packagenames. The @staticmethod is
purely there to allow easy testing (just call packagenames.map(doc) etc. on
an example doc. If there is interest, i can see to release that code
sometime.
cheers,
holger
--
http://holgerkrekel.net
On Thu, Dec 13, 2012 at 6:24 PM, Alexander Shorin <kx...@gmail.com> wrote:
> Hi Holger!
>
> Take a look on:
> http://code.google.com/p/couchdb-python/issues/detail?id=146
> it contains up-to-dated query server with support of all design
> function in Python. With latest patch you'll find short rst guide
> about how to start writing Python ddocs and what their differences
> from Javascript ones.
> --
> ,,,^..^,,,
>
>
> On Thu, Dec 13, 2012 at 6:59 PM, Holger Krekel <ho...@gmail.com>
> wrote:
> > Besides view functions, is it possible to write show/list functions in
> > python?
> >
> > I saw and old issue and patch about this at
> > http://code.google.com/p/couchdb-python/issues/detail?id=78
> >
> > But not anything in the docs. If it's not available is this planned?
>
Re: writing show/list functions in python
Posted by Alexander Shorin <kx...@gmail.com>.
Hi Holger!
Take a look on:
http://code.google.com/p/couchdb-python/issues/detail?id=146
it contains up-to-dated query server with support of all design
function in Python. With latest patch you'll find short rst guide
about how to start writing Python ddocs and what their differences
from Javascript ones.
--
,,,^..^,,,
On Thu, Dec 13, 2012 at 6:59 PM, Holger Krekel <ho...@gmail.com> wrote:
> Besides view functions, is it possible to write show/list functions in
> python?
>
> I saw and old issue and patch about this at
> http://code.google.com/p/couchdb-python/issues/detail?id=78
>
> But not anything in the docs. If it's not available is this planned?