Cloudant提供托管CouchDB,免费入门级别允许每月6 6GB的IO。对学习CouchDB的开发人员来说很好。
由于CouchDB允许在Javascript中指定map/reduce函数,因此通过在Classic ASP中运行的Javascript连接到它可能是有意义的。
有可能吗?
发布于 2012-06-29 15:34:21
是啊,有何不可?
Cloudant可以通过HTTP/REST访问。没什么特别的。
ASP Classic / Javascript可以使用MSXML2.ServerXMLHttp发送请求,这与在客户端Javascript上使用XMLHttpRequest的方式非常相似。
最好的是一个用于CouchDB的Javascript库,它不会假设它是在浏览器中运行的,也不会在Node中运行,因为ASP Classic不是这两种库中的一种。这是一个开始:
https://gist.github.com/3016476
示例ASP代码:
var creds = getCloudantCredentials("cloudantCreds.txt");
var couch = new CouchDB(couchUrl);
couch.connect(creds[0],creds[1]);
var r = couch.listDbs();
say("all dbs: " + JSON.stringify(r, null, 2));
r = couch.view('dbname', 'baseViews', 'bywords',
{ include_docs: false,
key: "whatever",
reduce:true} );
say("view: " + JSON.stringify(r, null, 2));下面是创建一组视图的方法:
function createViews(dbName, viewSet) {
var r, doc,
empty = function(doc) {
if ( ! doc.observation || doc.observation === '') {
emit(null, doc);
}
},
bywordsMap = function(doc) {
var tokens, re1,
uniq = function(a) {
var o = {}, i = 0, L = a.length, r = [];
for (; i < L; i++) {
if (a[i] !== '' && a[i] !== ' ') {
o[a[i]] = a[i];
}
}
for (i in o) { r.push(o[i]); }
return r;
};
if ( doc.observation && doc.observation !== '') {
tokens = uniq(doc.observation.split(/( +)|\./));
if (tokens && tokens.length > 0) {
tokens.map(function(token) {
emit(token, 1);
});
}
}
};
viewSet = viewSet || 'baseViews';
try {
r = couch.deleteView(dbName, viewSet);
doc = { views: { empty: { map:stringRep(empty) },
bywords: { map:stringRep(bywordsMap)}}};
r = couch.createView(dbName, viewSet, doc);
}
catch (exc1) {
say ('createViews() failed: ' + JSON.stringify(exc1));
}
}
function stringRep(fn) {
return fn.toString()
.replace(/[\s\t]*\/\/.*$/gm, '') // comments
.replace(/\n */gm, ' ')
.replace(/\r */gm, ' ')
.replace(/\{ +/gm, '{')
.replace(/ +\}/gm, '}');
}https://stackoverflow.com/questions/11257769
复制相似问题