Wednesday, 17 May 2017

How to get result from mysql database in sails rest service

I am using http://sailsjs.com/ framework for creating rest services. I am using mysql database for which I have installed https://www.npmjs.com/package/sails-mysql

npm install sails-mysql

I have done below changes in connections.js and models.js in config directory to establish a connection with mysql database.

connections.js

mysql: {
    adapter: 'sails-mysql',
    host: 'localhost',
    port: 3306,
    user: 'root',
    password: 'root',
    database: 'books'
}

models.js

connection: 'mysql'

I have this Books.js model in models directory

module.exports = {
  attributes: {
    id: 'integer',
    bookName: 'string',
    author: 'string',
    genre: 'string'
  }
};

I am not sure where I should fetch result of books database either in controller or in service ? Can anyone explain what is the way to do this ?



via Williams

No comments:

Post a Comment