In Postgresql, I want to call 3rd party libraries like moment.js or AWS lambda JS Client to invoke serverless functions from within the DB. I don't see any docs or examples how to do so: https://github.com/plv8/plv8/blob/master/README.md
Is this possible and where can I find examples of how to 'import' or 'require' additional libraries?
The plv8 language is trusted so there is no way to load anything from the file system. However you can load modules from the database.
Create a table with source code of a module and load it using
select
andeval()
. A simple example to illustrate the idea:Load the module from
js_modules
in your function:You can find a more elaborate example with an elegant
require()
function in this post: A Deep Dive into PL/v8.. Its is based onplv8.start_proc
(see also a short example here).