Auto loads waterline models from a directory
MIT License
Auto loads waterline models from a directory
Looking for another maintainer. I no longer use waterline and would like to have someone else take over. If you are interested, please reach out. Otherwise, eventually I will have this package removed. I doubt this module is used enough for people to read this, but in case it is read, there's your notice.
npm install --save waterline-models
models/user.js
module.exports = {
identity: 'user',
connection: 'default',
attributes: {
firstName: 'string',
lastName: 'string'
}
};
app.js
var path = require('path');
var waterlineModels = require('waterline-models');
waterlineModels.init({
dir: path.join(__dirname, 'models'),
adapters: {
memory: require('sails-memory-adapter')
},
connections: {
default: {
adapter: 'memory'
}
}
});
// This could be in another file
var User = require('waterline-models')('user'); // pass in the identity
User
.then(function (Model) {
return Model.create({
firstName: 'Jack',
lastName: 'Bliss'
});
})
.then(function (user) {
console.log(user);
// {
// firstName: 'Jack',
// lastName: 'Bliss',
// createdAt: Some Date,
// updatedAt: Some Date,
// id: 1
// }
});
cwd
The cwd directory to work off of when reading from the models directory
Default: process.cwd()
dir
The path to your models directory
Default: 'models'
defaultCollection
All other options are passed into waterline's initialize
method as the
configuration which is documented
here.