0

I am using sails.js with postgres as the database. Although most of the actions can be easily handled via waterline ORM, there are certain cases I prefer to use native queries and sometimes even postgres' native stored functions. However, the challenge with stored functions is that they come with an overhead of code maintenance.

In my project repo, I have created a directory sql which contains all the SQL functions. Currently, I have to manually make sure that whenever I am making some changes to a function, I need to recompile it on database.

I need to configure it such that these are compiled whenever I restart the server, just like all the models are re-created. Is it possible to do this and how ?

Travis Webb
  • 14,688
  • 7
  • 55
  • 109
Mandeep Singh
  • 7,674
  • 19
  • 62
  • 104

1 Answers1

1

Sails doesn't have any built-in support for compiling Postgres stored procedures, but you could make a Grunt task for this. Take a look at the documentation for tasks. These are run every time you lift Sails (and in some cases, when files are changed).

A quick Google found the grunt-pg-utils package, which might help you on your way.

sgress454
  • 24,870
  • 4
  • 74
  • 92
  • Looks like something I need exactly! Thanks a lot :-) – Mandeep Singh Aug 01 '14 at 19:39
  • Hello Scott, I managed to achieve this by copying the contents of sample grunt file mentioned on grunt_pg_utils page. But to run the task I have to execute the command grunt restore (restore being the task created to re-compile all store procedures. However, I am having trouble launching the task automatically at sails lift. Grunt configurations are quite different in sails 0.10.x as compared to 0.9.x – Mandeep Singh Aug 07 '14 at 11:21