Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Waterline model outside SailsJS api

Is it possible to use models defined within [app-name]/api/models outside api folder?

I have created separate folder in application root, where I placed cron job that should fill my database every hour. I would like to reuse Models defined inside my api folder, but not sure how to do it.

I see that I can do sails.lift inside that cron script but that doesn't seem very nice to me.

Did someone experience something similar? I'm new to node.js, so maybe I'm missing something pretty obvious.

like image 638
Ned Avatar asked Jun 09 '14 15:06

Ned


People also ask

How do you populate in sails JS?

populate() Modify a query instance so that, when executed, it will populate child records for the specified collection, optionally filtering by subcriteria . Populate may be called more than once on the same query, as long as each call is for a different association.

What is sails in node JS?

js (or Sails) is a model–view–controller (MVC) web application framework developed atop the Node. js environment, released as free and open-source software under the MIT License. It is designed to make it easy to build custom, enterprise-grade Node. js web applications and APIs.

What sails lift?

lift() Lift a Sails app programmatically. This does exactly what you might be used to seeing by now when you run sails lift . It loads the app, runs its bootstrap, then starts listening for HTTP requests and WebSocket connections.


1 Answers

If your concern with using sails.lift is that it starts an actual HTTP server that listens for requests, you can use sails.load instead. It will do everything that lift does--including loading hooks and models--except for starting the server.

var Sails = require('sails');
Sails.load(function(err, sails) {
   // At this point you have access to all your models, services, etc.
});
like image 186
sgress454 Avatar answered Oct 18 '22 19:10

sgress454