Pritam Parua
Pritam Parua

Reputation: 692

sails js getting data from database without schema definition in model

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

Answers (1)

mo.dhouibi
mo.dhouibi

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

Related Questions