【问题标题】:Architecting CouchDB with nodejs使用 nodejs 构建 CouchDB
【发布时间】:2014-08-15 23:48:09
【问题描述】:
有没有人在使用真正的 DAL 的 CouchDB 方面有任何经验? CouchDB 不像其他任何数据存储,尤其是。由于它的视图概念为数据添加了有趣的动态 - 业务逻辑分离......更不用说控制应用程序源代码的修订版了。
旁注:像 Nano 这样的库不是 DAL。它们类似于数据库驱动程序。直接从业务逻辑中使用 Nano 会将应用程序绑定到 CouchDB。不是我想要的。相反,我定制的 DAL 使用 Nano 作为驱动程序,但将业务逻辑与 Nano 完全分离。
问题:我应该阅读任何最佳实践或文档吗?任何现有的 DAL 可以在 MongoDB 和 CouchDB 之间切换以处理常见的事情(作为我正在尝试做的事情的起点)?
【问题讨论】:
标签:
node.js
couchdb
couchdb-nano
【解决方案1】:
您可能想查看资源丰富的https://github.com/flatiron/resourceful 它支持多种数据适配器,包括 mongodb 和 couchdb
这是一个简单的用例:
var resourceful = require('resourceful');
var Creature = resourceful.define('creature', function () {
//
// Specify a storage engine
//
this.use('couchdb');
//
// Specify some properties with validation
//
this.string('diet');
this.bool('vertebrate');
this.array('belly');
//
// Specify timestamp properties
//
this.timestamps();
});
//
// Now that the `Creature` prototype is defined
// we can add custom logic to be available on all instances
//
Creature.prototype.feed = function (food) {
this.belly.push(food);
};