canonic-epicure / KiokuJS-Backend-CouchDB

CouchDB backend for KiokuJS
3 stars 1 forks source link

Scope:createView can't add several views #1

Closed bergmark closed 13 years ago

bergmark commented 13 years ago

It takes only one view as args, and adding a second one causes an Exception.Conflict.

Working solution:

        __createViews : function (designDoc, args) {

            var doc = {
                ID          : '_design/' + designDoc,
                views       : {}
            }

            Joose.A.each(args, function (arg) {

                var view = doc.views[arg.name] = {}

                view.map = arg.map.toString()

                if (arg.reduce) view.reduce = arg.reduce.toString()

            })

            this.insertEntry(doc, 'store').now()

        },
bergmark commented 13 years ago

... and sample usage

backend.__createViews("all", [{
  name : "User",
  map : function (doc) {
    if (doc.className === "User") {
      emit(null, doc);
    }
  }
}, {
  name : "Transaction",
  map : function (doc) {
    if (doc.className === "Transaction") {
      emit(null, doc);
    }
  }
}]).now();
bergmark commented 13 years ago

Closing this, check the pull request instead.