我刚刚从 npm 下载了 Waterline。我有一些文件夹,但找不到我在哪里可以设置主机/用户/密码等来连接我的 postgress 数据库。我看了水线文件夹中的所有文件,什么也没有。谁能告诉我在哪里设置?
问问题
3547 次
1 回答
10
Waterline目前是Sails框架的子项目。
您正在搜索的是放置数据库配置的常规位置。当使用 Waterline 作为 Sails 的一部分时,此约定将通过 Sails 自动将配置文件添加到全局sails
对象中的方式来定义。
单独使用 Waterline 时,您必须自己处理这部分:您希望引导并将配置显式传递到 waterline。您必须逐步执行的操作:
- 在您的情况下,需要 Waterline 和正确的 Waterline 适配器:sails-postgresql
- 指定
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
});
于 2014-02-24T09:40:59.003 回答