如何在CouchDB中的视图之间共享代码?
Jesse Hallett 有一些很好的实用方法,包括
function dot(attr) {
return function(obj) {
return obj[attr];
}
}
Array.prototype.map = function(func) {
var i, r = [],
for (i = 0; i < this.length; i += 1) {
r[i] = func(this[i]);
}
return r;
};
...
Run Code Online (Sandbox Code Playgroud)
我在哪里可以放置此代码,以便每个视图都可以访问它?
类似于我在我的应用程序中使用的常量.我在哪里放
MyApp = {
A_CONSTANT = "...";
ANOTHER_CONSTANT = "...";
};
Run Code Online (Sandbox Code Playgroud)
如果我想要一个过滤"是这个有钱人吗?"的视图怎么办?
function(doc) {
if (doc.type == 'person' && doc.net_worth > 1000000) {
emit(doc.id, doc);
}
} …Run Code Online (Sandbox Code Playgroud) 我一直在看到" CouchDB可能不是各种情况下最好的工具"的想法.这很有用,但不幸的是也适用于所有技术.
更有用的是描述如何在项目上尝试CouchDB并随后放弃传统的SQL数据库.
如果你在一个项目上尝试过CouchDB,然后又回到SQL数据库,那么哪些因素起了最大的作用?