Reputation: 2163
We have a legacy app that has a MySQL database. It's backend is currently written in PHP.
We are now revamping the backend and building a backend in node.js. The tech team has decided to use sails.js as their framework for building this backend.
Sails.js by default uses Waterline (ORM).
What we want is to be able to connect to our legacy MySQL database and drop orm support in our sails app.
When initializing a new sails app, I passed a without
option to opt out of orm in my app.
Now, I am confused as to where (and how) should I connect to the legacy MySQL database in a single place and make that connection available to all the controllers/action files that we will have.
Do I still have to use sails-mysql, or should I use any other adapter that helps me connect to the database? Where should this code live? Inside a helper method ?
Any help would be appreciated!
Upvotes: 2
Views: 291
Reputation: 994
If you created the application with --without orm
then you basically disabled any ORM/model/database functionality that Waterline/Sails offer. That means, you cannot use the models concept as documented in Sails.
You can always use other methods, just do it like in any other node.js project. Require the module, and follow their documentation. Check http://docs.sequelizejs.com/ for one of the many options available.
And about using sails-mysql, that is just an "adapter" for Watermark that tells your connection that you want to use 'mysql'. But that is only available when you do have ORM configured in your application.
If I were to develop the application without ORM, I would create "services", called then in controllers. That is, build your business logic in /api/services
(create the folder if it doesn't exist) and then develop your solution there. Finally call them from your controllers. You can check my other answer here for an example
Upvotes: 1