admin管理员组文章数量:1306784
I just downloaded Waterline from npm. I got some folders, but cant find where can i set the host/user/password etc. to connect my postgress database. I watched all files in the waterline folder and nothing. Can anyone tell me where set it ?
I just downloaded Waterline from npm. I got some folders, but cant find where can i set the host/user/password etc. to connect my postgress database. I watched all files in the waterline folder and nothing. Can anyone tell me where set it ?
Share Improve this question edited Apr 4, 2015 at 2:31 Travis Webb 15k9 gold badges58 silver badges110 bronze badges asked Feb 18, 2014 at 22:05 CSharpBeginnerCSharpBeginner 1,7256 gold badges24 silver badges39 bronze badges 1- 2 Any issues with the provided answer? – marionebl Commented Feb 27, 2014 at 11:12
1 Answer
Reset to default 10Waterline is in its current state a sub project of the Sails framework.
What you are searching for is the conventional place to put your database configuration. When using Waterline as part of Sails this convention would be defined by the way Sails auto-requires configuration files into the global sails
object.
When using Waterline on its own you'll have to take care of this part for yourself: You want to bootstrap and pass your configuration explicitly into waterline. What you'll have to do step by step:
- Require Waterline and the correct Waterline adapter, in your case: sails-postgresql
- Specify
adapters
config - Specify
connections
config, this will take the config in question - Define and load your
collections
- Initialize Waterline
An example how to do all this, derived from these Waterline examples: https://github./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
});
本文标签: javascriptHow to set database connection string in Waterline ORMStack Overflow
版权声明:本文标题:javascript - How to set database connection string in Waterline ORM - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741822263a2399435.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论