node.js - "describe"和 "schema.define"和有什么区别?

标签 node.js compoundjs jugglingdb

随着我在CompoundJS世界中的进步,我遇到了两种定义模式的方法:

第一:

var Product = describe('Product', function () {
  property('upc', String);
  property('name', String);
  set('restPath', pathTo.products);
});

第二:

var Schema = require('jugglingdb').Schema;
var schema = new Schema('memory');

var Product = schema.define('Product', {
  upc: { type: Number, index: true },
  name: { type: String, limit: 150, index: true },
  createdAt: { type: Date, default: Date.now },
  modifiedAt: { type: Date, default: Date.now }
}, {
  restPath: pathTo.products
});

第一个可以工作,但看起来像一个旧的设计。第二个不起作用,但这是根据 JugglingDB 文档执行此操作的方法。

我应该使用哪一个?为什么第二个对我不起作用?

更新: 这是我使用第二个时遇到的错误:

Express
500 TypeError: Cannot call method 'all' of undefined in products controller during "index" action

at Object.index (C:\Users\Eran\Documents\Relay Foods\nutrition-facts-editor\app\controllers\products.js:47:13)
at Array.2 (C:\Users\Eran\Documents\Relay Foods\nutrition-facts-editor\node_modules\compound\node_modules\kontroller\lib\flow-control.js:150:28)
at ActionContext.run [as innerNext] (C:\Users\Eran\Documents\Relay Foods\nutrition-facts-editor\node_modules\compound\node_modules\kontroller\lib\flow-control.js:103:31)
at Controller.BaseController.next (C:\Users\Eran\Documents\Relay Foods\nutrition-facts-editor\node_modules\compound\node_modules\kontroller\lib\base.js:107:22)
at Controller.protectFromForgery (C:\Users\Eran\Documents\Relay Foods\nutrition-facts-editor\node_modules\compound\node_modules\kontroller\lib\helpers.js:76:21)
at Object.protectFromForgeryHook (C:\Users\Eran\Documents\Relay Foods\nutrition-facts-editor\app\controllers\application.js:3:13)
at Array.1 (C:\Users\Eran\Documents\Relay Foods\nutrition-facts-editor\node_modules\compound\node_modules\kontroller\lib\flow-control.js:150:28)
at run (C:\Users\Eran\Documents\Relay Foods\nutrition-facts-editor\node_modules\compound\node_modules\kontroller\lib\flow-control.js:103:31)
... snip ...

最佳答案

我认为describedefine是相同的。这里的问题是使用范围,在我的第一个实现中是全局的,在第二个实现中是本地的。因此,我需要它是全局的,以便与应用程序的其余部分一起工作。

关于node.js - "describe"和 "schema.define"和有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16254492/

相关文章:

node.js - 在 Heroku 上使用 NodeJS 进行 HTML5 音频转换

javascript - NodeJS超测访问 session 对象

node.js - CompoujdJS 生成器丢失

node.js - 脚手架复合js时路由中的拼写错误问题

node.js - 模型似乎没有关于CompoundJS和MongoDB的信息

mysql - Compoundjs 无法与 jugglingdb-mysql 一起运行

javascript - hapijs 自定义 http 状态消息

javascript - 使用 JavaScript/Node.js 从 IP 地址获取两个字母的大陆代码

node.js - Node js,使用 connect-memcached 时没有返回响应

node.js - 防止 jugglingDB 中的构造函数设置模型属性