【发布时间】:2014-03-18 22:57:15
【问题描述】:
我刚刚从 npm 下载了 Waterline。我有一些文件夹,但找不到我在哪里可以设置主机/用户/密码等来连接我的 postgress 数据库。我看了水线文件夹中的所有文件,什么也没有。谁能告诉我在哪里设置?
【问题讨论】:
-
提供的答案有什么问题吗?
标签: javascript node.js orm sails.js waterline
我刚刚从 npm 下载了 Waterline。我有一些文件夹,但找不到我在哪里可以设置主机/用户/密码等来连接我的 postgress 数据库。我看了水线文件夹中的所有文件,什么也没有。谁能告诉我在哪里设置?
【问题讨论】:
标签: javascript node.js orm sails.js waterline
Waterline 在其当前状态下是Sails 框架的子项目。
您正在搜索的是放置数据库配置的常规位置。当使用 Waterline 作为 Sails 的一部分时,此约定将通过 Sails 自动将配置文件放入全局 sails 对象的方式来定义。
当单独使用 Waterline 时,您必须自己处理这部分:您希望引导并将您的配置显式传递到 waterline。你必须一步一步做的事情:
adapters配置connections 配置,这将采用有问题的配置collections
一个如何做这一切的例子,来自这些 Waterline 例子:https://github.com/balderdashy/waterline/blob/master/example/
// 1. Require Waterline and the correct Waterline adapter
Waterline = require('waterline'),
postgreAdapter = require('sails-postgresql');
var config = {
// 2. Specify `adapters` config
adapters: {
postgre: postgreAdapter
},
// 3. Specify `connections` config
postgreDev: {
adapter: 'postgre',
host: 'localhost',
database: 'development',
user: 'developer',
password: 'somethingsupersecret'
}
};
// 4. Define and load your collections
var User = Waterline.Collection.extend({
// collection.identity and collection.connection
// have to be specified explicitly when using Waterline without Sails
identity: 'user',
connection: 'postgreDev',
attributes: {
...
}
});
var waterline = new Waterline();
waterline.loadCollection(User);
// 5. Initialize Waterline
waterline.initialize(config, function(err, models) {
if (err) throw err;
// Expose your models for further use
});
【讨论】:
postgreDev... 包裹在connections 中,否则你会得到一个异常