Re: Javascript support in the backend, i.e. PL/JS

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Javascript support in the backend, i.e. PL/JS
Date: 2007-11-16 08:20:37
Message-ID: 162867790711160020h47f1cd62rbf91d15c1b9846d4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 16/11/2007, Sam Mason <sam(at)samason(dot)me(dot)uk> wrote:
> Hi All,
>
> I've been writing some code[1] to support Javascript in the backend.
> I've got the basic bits working, the next job for me is implementing
> SPI support. Currently, it runs simple bits of code like the
> following:
>
> CREATE FUNCTION jsinc(n INTEGER) RETURNS INTEGER LANGUAGE pljs AS $$
> return n+1;
> $$;

nice

Pavel

>
> It knows to compile the code inside a javascript function, passing the
> parameters with the specified names. If no names are specified, $n
> style naming is used--Javascript nicely deviates from C syntax in
> respect of allowing $ in parameter names. It knows how to handle
> boolean and numeric (int[248], float[48] and numeric) types are known
> about at the moment. Javascript has only one numeric type, so
> everything behaves as a double.
>
> For SPI, I'm thinking that I'd currently like to attempt some object
> orientated style interface. In simplest terms, it would look a bit
> like this:
>
> portal = {
> next : function () { return {} }
> close : function () { }
> }
>
> plan = {
> query : function (args,readonly) { return portal; }
> execute : function (args) { }
> close : function () { }
> }
>
> spi = {
> prepare : function (sql,argtypes) { return plan; }
> }
>
> So running some SQL would probably look something like:
>
> for (row in spi.prepare("SELECT 1 AS n").query()) {
> print(row.n);
> }
>
> The spi object would be passed into the javascript function as an extra
> parameter, maybe with the name "__spi" to avoid name clashes.
>
> I may put some shortcuts in if things turn out to be too slow later
> on, but I'd prefer not to. Most other languages seem to expose the
> SPI functions directly, but that seems like a bit of a waste in a
> language that should be able to do OO stuff. PL/Java seems to have
> its hands tied with JDBC, so I can't look there for much inspiration.
> Are there any other OO languages that do things well?
>
>
> Let me know what you think!
>
>
> Sam
>
> p.s. the main reason for doing this is because I think Javascript is a
> nice language!. Having said that, Nulls are handled very badly by
> javascript, so (1+null = 1) and ("_"+null+"_" = "_null_")!
>
> [1] http://xen.samason.me.uk/~sam/repos/pljs/
>
> It's definitely work in progress! I have fun with header
> clashes between Postgres and Spidermonkey---hence the split
> into C files.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at
>
> http://www.postgresql.org/about/donate
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Sam Mason 2007-11-16 08:29:49 Re: Javascript support in the backend, i.e. PL/JS
Previous Message Sam Mason 2007-11-16 08:10:43 Javascript support in the backend, i.e. PL/JS