Skip to content

Idea: register function in postgres-compatible way with plv8 #28

Description

@mmkal

It occurred to me that as well as the API-way of registering a function:

db.public.registerFunction({
            name: 'say_hello',
            args: [DataType.text],
            returns: DataType.text,
            implementation: x => 'hello ' + x,
})

Might it also be possible to enable "real" functions defined via SQL, as long as they use language plv8?

e.g.

create function say_hello(x text) returns text as
$func_delimiter$

return 'hello ' + x

$func_delimiter$
language plv8;

If pgsql-ast-parser is able to parse the create function query, it could be automatically mapped to the arguments required for registerFunction, where implementation is the eval(...) result of the body. That way, at least for plv8 functions, it'd be totally valid both in pg-mem and real postgres.

I'm interested in this as I have a library which implements row tracking through an in-memory JS git implementation: https://npmjs.com/package/plv8-git - I'm super curious if pg-mem could be used somehow to come full circle and even run the database in memory too.

Edit: just seen you have discussions enabled. I would have created this over there if I'd noticed, since it's not an issue. Feel free to move if you prefer it there too!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions