Created
March 28, 2016 15:28
-
-
Save edesilets/91d5d99f91cf47c5d80c 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'); | |
var wPsql = require('waterline-postgresql'); | |
// 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, | |
'psql': wPsql | |
}, | |
connections: { | |
default: { | |
//adapter: 'memory', | |
adapter: 'psql', | |
// Psql test START | |
database: 'homestatus', | |
host: '127.0.0.1', | |
user: 'pi', | |
password: 'password', | |
port: 5432, | |
ssl: false | |
// Psql test END | |
} | |
} | |
}; | |
// 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