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!
It occurred to me that as well as the API-way of registering a function:
Might it also be possible to enable "real" functions defined via SQL, as long as they use
languageplv8?e.g.
If pgsql-ast-parser is able to parse the
create functionquery, it could be automatically mapped to the arguments required forregisterFunction, whereimplementationis theeval(...)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!