postgresql – plv8 JavaScript语言扩展可以调用第三方库吗?
发布时间:2020-12-13 15:59:07 所属栏目:百科 来源:网络整理
导读:在 Postgresql中,我想调用第三方库,如moment.js或AWS lambda JS Client,以从DB中调用无服务器功能.我没有看到任何文档或示例如何执行此操作: ? https://github.com/plv8/plv8/blob/master/README.md 这是可能的吗?在哪里可以找到如何“导入”或“需要”其
在
Postgresql中,我想调用第三方库,如moment.js或AWS lambda JS Client,以从DB中调用无服务器功能.我没有看到任何文档或示例如何执行此操作:
? https://github.com/plv8/plv8/blob/master/README.md 这是可能的吗?在哪里可以找到如何“导入”或“需要”其他库的示例? 解决方法
plv8语言是可信的,因此无法从文件系统加载任何内容.但是,您可以从数据库加载模块.
创建一个包含模块源代码的表,并使用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()函数:A Deep Dive into PL/v8. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |