Postgresql and Node.js 100% Javascript Adventure – Part 2

This is the second part of PostgreSQL, Node.js and JavaScript post.

We can continue by installing PL/V8:

Then we can create the extension in our database.

And run SQL command below:

Then, we can create functions using PL/V8 JavaScript language. A simple example is below:

It gets variable inputs as JSON type. It returns a single variable result as JSON type. The inputs can have the structure for various parameters so that we can filter and return some records from a table or view. The outputs can include status, rows, error messages, etc. The next example is slightly more complicated:

This is a proof of concept that we can have a set of functions to provide CRUD operations, for instance, and even more advanced requirements. To be honest, for now, I cannot see a straight forward way to have OOP coding using this method.

Leave a Comment