Reputation: 692
I am new to SailsJs. I have a MySQL database with 123 tables with lots of fields. Now i want to use that database in my sails application. When i need to get data from any table i need to declare fields name, type etc in model like below
module.exports = {
tableName: 'Mytable',
adapter: 'someMysqlServer',
migrate: 'safe',
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
id: {
type: 'number',
required:true
},
name: {
type: 'string',
required: true
}
}
};
Now I don't want to declare all the fields in model as i have so many tables/fields. So how can i select/insert/update data without this.
Upvotes: 1
Views: 600
Reputation: 595
var connection = mysql.createConnection({
host: sails.config.connections.yourDbConnetion.host,
user: sails.config.connections.yourDbConnetion.user,
password: sails.config.connections.yourDbConnetion.password,
database: sails.config.connections.yourDbConnetion.database
});
YourFunction: function (req,res) {
connection.query('YOUR SQL QUERY ', function (err, result) {
if (err)
return res.send(err);
.........
});
}
Upvotes: 1