sails.js - Can I hook up a model to an existing database? -
i have mongodb sitting behind existing api , want migrate api utilize sailsjs.
the info construction isn't crazy - standard stuff using default mongodb objectids primary keys.
will able utilize existing db sails wiring sails models? need specify _id field? and, if so, datatype should use?
e.g. existing mongodb user collection next schema:
_id name fname lname age
can wire using next work?:
// user.js var user = { attributes: { name: { fname: 'string', lname: 'string' }, age: 'integer' } }; module.exports = person;
first: dont have define _id (waterline you)
waterline wants help using same functions , models types of databases. "sub-field" not supported in mysql example. don't work.
you can this:
// user.js var user = { attributes: { name: 'json', age: 'integer' } }; module.exports = user;
if want validate "name" can add together own validation:
// user.js var user = { types: { myname: function(json){ if(typeof json.fname == "string" && typeof json.lname == "string"){ homecoming true; }else{ homecoming false; } } }, attributes: { name: { type: "json", myname: true }, age: 'integer' } }; module.exports = user;
sails.js
No comments:
Post a Comment