-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New feature: generate trigger functions #38
Comments
Hey thanks for the detailed comment, I do not fully understand some things and have some follow up questions
|
i.e these variables are automatically provided by the global context
and also:
In short, a trigger function gets passed special vars that change depending wheter the trigger is a before/after insert and whether it is executed for each row In plv8ify, a trigger function should return a specific type (TRIGGER) and remove all parameters from the function |
Got it, thanks |
Sounds good! Thanks for the explanation, feel free to raise a PR, we can surely use such a feature! |
Closing, live in |
Hi, just started experimenting using plv8ify for one of our projects, and so far we're loving it.
Our Postgres data model is json heavy, and I am starting to struggle handling properly (as in, with types and not having to build json objects manually every time) backed heavy stored procedures.
I think plv8ify would be a perfect fit for our use case, as. it would allow us to use typing to write code and at the same time depoy such code in the database.
I think I could work on a PR to add the capability of detecting trigger functions and handling the proper PLV8 code generation
E.G., I'd like to be able to define a trigger function plv8ts style:
and have typescript support for the NEW and OLD object, and at the same time be able to auto generate the trigger function with the proper syntax.
The only challenge I see is establishing a proper pattern for identifying a trigger function: ts-morph properly detects the custom type, but it returns something like this in the returnType field:
The easiest path for identifying a trigger function would be to 'decorate' the function with a comment that includes a specific keyword like 'plv8_trigger' and handling things from there.
I feel like adding a generic rule to determine whether a function is a trigger or not would be tricky and prone to errors (other than forcing the return type to have a fixed keyword in the name)
e.g. something like:
would then be easy to catch and handle in the getPLV8SQLFunction function to properly strip the input params
I do have a local prototype working for this functionality, just let me know if that would be an acceptable feature to be added
The text was updated successfully, but these errors were encountered: