Added Connection Configuration
Open /config/connections.js
******************************
module.exports.connections = {
mysql: {
module : 'sails-mysql',
host : 'localhost',
user : 'root',
password : 'password',
database : 'test'
}
Go to /config/models.js
***************************
module.exports.models = {
connection: 'mysql',
GO to api/models/User.js
****************************
module.exports = {
connection: 'mysql',
attributes: {
name:{
type:"string",
required:true,
minLength: 2
},
empnum:{
type:"string",
required:true
},
email:{
type:"email",
required:"true",
unique: true
}
}
};
GO to api/controllers/UserController.js
*****************************************
module.exports = {
'registration': function(req,res){
res.view();
},
create: function(req,res,next){
User.create(req.params.all(), function userCreated(err,User){
if(err){
return next(err);
}
else{
return res.send("Data Saved Successfully");
}
});
}
}
Type : http://localhost:1337/User
Open /config/connections.js
******************************
module.exports.connections = {
mysql: {
module : 'sails-mysql',
host : 'localhost',
user : 'root',
password : 'password',
database : 'test'
}
Go to /config/models.js
***************************
module.exports.models = {
connection: 'mysql',
GO to api/models/User.js
****************************
module.exports = {
connection: 'mysql',
attributes: {
name:{
type:"string",
required:true,
minLength: 2
},
empnum:{
type:"string",
required:true
},
email:{
type:"email",
required:"true",
unique: true
}
}
};
GO to api/controllers/UserController.js
*****************************************
module.exports = {
'registration': function(req,res){
res.view();
},
create: function(req,res,next){
User.create(req.params.all(), function userCreated(err,User){
if(err){
return next(err);
}
else{
return res.send("Data Saved Successfully");
}
});
}
}
Type : http://localhost:1337/User