Skip to content

Instantly share code, notes, and snippets.

@edesilets
Created March 28, 2016 15:23
Show Gist options
  • Save edesilets/7ab484b92a0ed8b865f8 to your computer and use it in GitHub Desktop.
Save edesilets/7ab484b92a0ed8b865f8 to your computer and use it in GitHub Desktop.
var Waterline = require('waterline');
var sailsMemoryAdapter = require('sails-memory');
// Create the waterline instance.
var waterline = new Waterline();
// Create a specification for a User model.
var userCollection = Waterline.Collection.extend({
identity: 'user',
connection: 'default',
attributes: {
firstName: 'string',
lastName: 'string',
}
});
// Add the models to the waterline instance.
waterline.loadCollection(userCollection);
// Set up the storage configuration for waterline.
var config = {
adapters: {
'memory': sailsMemoryAdapter,
},
connections: {
default: {
adapter: 'memory',
}
}
};
// Initialise the waterline instance.
waterline.initialize(config, function (err, ontology) {
if (err) {
return console.error(err);
}
// Tease out fully initialised models.
var User = ontology.collections.user;
// First we create a user.
User.create({
firstName: 'Neil',
lastName: 'Armstrong'
})
.then(function (user) {
return user.save();
})
.then(() => User.find())
.then(console.log)
.catch(console.error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment