Created
March 28, 2016 15:23
-
-
Save edesilets/7ab484b92a0ed8b865f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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