What is the difference between "describe" and "schema.define"?

586 Views Asked by At

As I've progressed thru the world of CompoundJS I've came across two ways of defining a schema:

First:

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

Second:

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
});

The first, works, but looks like an old design. The second, does not work, but this is the way to do it according to JugglingDB docs.

Which one should I use? Why wouldn't the second one work for me?

UPDATE: This is the error I get when I use the second one:

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 ...
1

There are 1 best solutions below

0
On

I think that describe and define are the same. The issue here is the usage scope which is global in my first implementation and local in the second one. So I'll need it to be global in order to work with the rest of the application.