plv8 | V8 Engine Javascript Procedural Language add-on | Database library
kandi X-RAY | plv8 Summary
kandi X-RAY | plv8 Summary
PLV8 - A Procedural Language in Javascript powered by V8.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of plv8
plv8 Key Features
plv8 Examples and Code Snippets
Community Discussions
Trending Discussions on plv8
QUESTION
Is something like PLV8 exist in Microsoft SQL Server (JavaScript procedural language add-on for Microsoft SQL Server)?
...ANSWER
Answered 2020-Oct-24 at 02:38You can utilise the CLR integration in MS SQL Server, and write managed code (C# / VB.Net / possibly other languages) that you will be able to execute from within SQL Server.
Having said that, the fact that such a possibility exists doesn't necessarily imply that it should be used. Very few tasks actually benefit from being implemented in managed code compared to T-SQL, such as (the list is by no means complete):
- Computationally heavy string manipulations, including regexps (the latter has no alternative in T-SQL);
- Communication with objects external to SQL Server (file system, various API endpoints, etc.);
- Possibility to implement autonomous transactions.
Before going this way, make sure your team understands performance and security implications related to this approach, as they are many. The aforementioned link gives you a good starting point.
QUESTION
I am having trouble executing this query
...ANSWER
Answered 2020-May-15 at 16:56I don't use plv8, but IN works with lists and lists can't be stored in parameters. What you appear to have is an array. For arrays, you use:
QUESTION
I'm currently trying to convert a PostgreSQL function from JS to Perl since the PLV8 extension isn't available in my environment.
The original JS/PLV8 code I have is:
...ANSWER
Answered 2020-Jan-28 at 11:21I am not familiar with PostgreSQL, but looking at your code sample, here are some comments:
$TG_OP = 'UPDATE'
: string comparison in Perl is done with theeq
operator$OLD.user_id !== $NEW.user_id
: numerical comparison for non-equality should be done using the!=
operatornull
should probably beundef
.$userId = OLD.user_id
: it seems like$OLD
is an object (by looking at your code)? Then you should probably access theuser_id
attribute using something like$OLD->user_id
. The same goes for all other attribute accesses using the dot.
operator in Javascript; those should probably be a->
operator in Perl.NOTICE 'Update of user_id not allowed: %, at %'
: you can throw an exception in Perl using thedie
functionIF
...ELSE
: In Perl this isif
...else
Math.max($cashOut - $bet, 0)
: In Perl you can usemax
from the moduleList::Util
QUESTION
I've a resource that gets acquired from distributed clients. This resource is protected by a transaction level lock:
SELECT pg_advisory_xact_lock(123456)
I know I can use pg_try_advisory_xact_lock
if I don't want to wait for it to be free. If I got it - the call would return true
, otherwise false
.
What I would like to achieve is the behaviour of pg_advisory_xact_lock
with queue-size. If less than 4 transactions are waiting from the lock join them in waiting, otherwise return false pg_try_advisory_xact_lock
otherwise. If you managed to get the lock - return true.
Can I achieve this without writing a plv8 extension? Any ideas?
I'm using PostgreSQL 10.
...ANSWER
Answered 2019-Dec-03 at 18:16Cycle through "pg_try_advisory_xact_lock(...)" on 5 different lock ids (say 123457 to 123461) (1 real lock holder and 4 more non-holding waiters = 5). Getting one of those then grants you the right to wait on the "real" lock id. Failing to get any of the 5 results in failure. This does mean you have to reserve/coordinate 6 magic constants, rather than 1.
QUESTION
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?
...ANSWER
Answered 2017-Jul-16 at 17:20I have two hints pointing in the NO direction:
You can use
PLV8
in Amazon RDS PosgreSQL. RDS doesn't allow any language which is not trusted. As explained in PostgreSQL documentation:TRUSTED
TRUSTED
specifies that the language does not grant access to data that the user would not otherwise have.If PLV8 could use libraries, those would (most probably) allow for performing operations such as downloading data via HTTP, or checking the file system, which would contravene this restriction (and possibly, put RDS system at hacking risk).
Presentation PLV8 - The PostgreSQL web side by Lucio Grenzi.
Slide #10:
PLV8: a trusted language
[...]
- no way to load external processing modules from the file system
A possible alternative
I have used the PLPERLu
(u
meaning untrusted) language. Using that language, you can use
libraries. Your libraries should be in the standard locations for the PERL installation being used by PostgreSQL (as defined when you CREATE LANGUAGE
).
QUESTION
I'm trying to build a PostgreSql 9.6 docker image that has plv8 extension installed. Below is my Dockerfile.
...ANSWER
Answered 2018-Jul-17 at 14:31Try to run commands using && as possible as you can. Example:
QUESTION
I wanted to drop in google's open location code javascript implementation into PostgreSQL (using the plv8 extension) and make it available to encode/decode from PostGIS geometry/geography data types.
While I was successful, I wasn't able to work out how to only create a single function for the https://github.com/google/open-location-code/blob/master/js/src/openlocationcode.js file and I ended up putting a copy of that function into each function where I needed to encode/decode plus codes. When I attempted to pull it out into its own function, I could either get a string containing javascript or a string of [Object],[object] rather than a callable function.
Is this possible with the plv8 extension in PostgreSQL?
Incomplete code snippet example (full version here):
...ANSWER
Answered 2018-Apr-03 at 19:45You have two options.
Store the source code of the function in a special database table and load it using
select
andeval()
. Read about details in this answer: Can plv8 JavaScript language extension call 3rd party libraries?Place the function in an initialization module and set this module using configuration parameter
plv8.start_proc
so it is executed automatically on start-up. You can find details in the PL/v8 documentation.
The second option is really handy and does not need an additional table, but may seem a bit tricky. A simple example: we want to have a function square_of_sum(a, b)
predefined in all our plv8 functions. First, create the initialization function:
QUESTION
I have database design (in PostgreSQL 9.6) where in one table company data is stored. Each company can have one or more contact persons whose details are layed out in another table. The (simplified) schema being something like that:
...ANSWER
Answered 2017-Nov-14 at 11:01I would use common relational approach for M:N cardinality
QUESTION
I'm having trouble wrapping my head around this context. Here's my first take at this using some of the built in functions:
What I've tried so far ...ANSWER
Answered 2017-Jul-12 at 17:34Example table:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install plv8
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page