如何将一个variables传入Kraken.js模型?

我有一个variables,持有我的Sequelize连接,如下所示:

var sequelize = new Sequelize('database', 'username'); 

有了Kraken.js,我怎么把它传递给模块呢? 我没有看到我可以在index.jsconfiguration文件中添加这个…

谢谢!

(我不能把这个标记为krakenjs,因为我没有足够的业力。)

这是一个非常类似于本指南中所示的设置:

http://sequelizejs.com/articles/express

您将创build模型文件(在./models下)。 您需要使用associatefunction注册该模型(请参阅上一个链接)。

而要真正使用该模型,您可以复制与Kraken购物车示例相同的用法https://github.com/lmarkus/Kraken_Example_Shopping_Cart/

例如:(注册完模型后)

 'use strict'; var Product = require('../models/productModel'); module.exports = function (server) { /** * Display a list of the products. */ server.get('/', function (req, res) { Product.find(function (err, prods) { res.render('index', products); }); }); }; 

您可以将连接添加到单独的文件并将其导出( http://openmymind.net/2012/2/3/Node-Require-and-Exports/ )。 我将这些文件存储在一个名为lib /

然后在index.js(应用程序的起点)使用导入文件

 require("./lib/.."). 

然后在index.js中调用它

 app.configure = function configure(nconf, next) {...}; 

http://krakenjs.com/#structure_of_a_project

一个很好的示例应用程序是https://github.com/lmarkus/Kraken_Example_Shopping_Cart