1

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.

1 Answer 1

1
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);
.........

});
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.