Can plv8 extend JavaScript to third-party libraries?

In Postgresql, I want to call third-party libraries, such as instant.js or AWS lambda JS Client, to call serverless functions from the database. I do not see any documents or examples of how to do this:   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?

+4
source share
2 answers

The plv8 language is trusted, so there is no way to download anything from the file system. However, you can load modules from the database.

, select eval(). , :

create table js_modules (
    name text primary key,
    source text
);

insert into js_modules values
('test', 'function test() { return "this is a test"; }' );

js_modules :

create or replace function my_function()
returns text language plv8 as $$
//  load module 'test' from the table js_modules
    var res = plv8.execute("select source from js_modules where name = 'test'");
    eval(res[0].source);
//  now the function test() is defined
    return test();
$$;

select my_function();

CREATE FUNCTION
  my_function   
----------------
 this is a test
(1 row) 

require() : PL/v8. , plv8.start_proc (. ).

+6

, :


PLPERLu (u ) . , use . PERL, PostgreSQL ( CREATE LANGUAGE).

0

Source: https://habr.com/ru/post/1681559/


All Articles