couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kowsik <kow...@gmail.com>
Subject Help with Erlang views
Date Wed, 05 Oct 2011 04:32:13 GMT
Was chatting with @jchris about erlang views and would love to get
some help on this. On blitz.io we are in the process of investigating,
experimenting with Erlang views. Purely from an operational
perspective, we are not trying to become Erlang hackers. Just need to
know enough to be dangerous and make our CouchDB clusters fly and
scale out. :)

We are already using the built-in reduce functions and I as looked
through all of our design views, they mostly fall into the following
two buckets. I'm suspecting most other users' map functions fall into
this category.

function(doc) {
    if (doc.type === "foo" and doc.foo) {
        emit(Date.parse(doc.created_at), null);
    }
}

@jchris pointed me to this https://github.com/daleharvey/dh_date but
would be awesome to see this part of utils:date_parse or date:parse as
a built-in function that can handle both strftime("%Y/%m/%d %H:%M:%S
+0000") as well as iso8601. This is a fairly common use case for us.

Next one is this:

function(doc) {
    if (doc.type === "foo" && doc.foo) {
        for (i in doc.foo) {
            if (doc.hasOwnProperty(i)) {
                emit(doc.foo[i], null);
            }
        }
    }
}

Pretty much everything we have falls into using Date.parse or
iterating over an array/object to emit a bunch of KVs. Can someone
help translate this to Erlang please? I have googled around and seen a
few examples. The latter has some online examples using list:foreach,
but Date.parse didn't seem to have any.

Thanks and much appreciated,

K.
---
http://blog.mudynamics.com
http://blitz.io
@pcapr

Mime
View raw message