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
Represent stored routines and provide type safe way to execute them #5253
Comments
I have no idea what's this supposed to be doing, but feel free to PR it 😄 Just keep in mind the schema comparator needs to be able to detect if something is already in the schema (or is this runtime only?). The new decorator feels also pretty weird to me, I would rather have some new options instead, or we need a more specific name. One note - |
ok. Edited the above example, before I forget.
The decorators are declaring a stored function/procedure (in the example, a procedure). Each class member represents an input param. And the other options are part of the class decorator. https://dev.mysql.com/doc/refman/8.0/en/create-procedure.html And the second code block shows how you'd use the declared class in the application code.
No. Not only runtime. Also migration generation time. The schema comparator can look up information_schema in the case of MySQL and whatever is the equivalent in PostgreSQL... The same schema looked up during entity generation, which I'm guessing (I haven't looked deep into it yet...) is also used in schema comparator. I haven't examined PostgreSQL in detail, but I know for sure MySQL has all the needed info in its information_schema, including even the SQL source of routines, so the comparator should be able to detect if the declaration matches what is already in DB, and generate a drop + create if there are any differences detected, including (most notably) differences in the body of the stored routine.
Stored routines behave very differently from entities, so I think overloading the Or do you mean the
Great. Yes, I do plan to PR it, but I wanted to get your opinion on the proposed design first. EDIT: Wait... Ref is already required anyway for out and inout params, so I guess |
Thanks, will take a look during next week and try to get acquainted with this to have some opinion :]
This is more about what the actual decorators should be doing. If you want to modify the metadata object, we dont need a new one, I don't understand what you mean by in/out params, so let's first agree on the meaning of that (and the actual implementation), then we can discuss the decorators. Feel free to use those proposed names in the initial PR and we can find better ones (or maybe not) later during reviews. (and if this is all explained in the links you provided, please allow me a few days, I don't have time to read through them this weekend) |
Sure thing 👍 It is explained in the docs indeed. Here's a more full collection of links for your reading pleasure when you have more time: https://dev.mysql.com/doc/refman/8.0/en/create-procedure.html https://www.postgresql.org/docs/current/sql-createfunction.html https://github.com/WiseLibs/better-sqlite3/blob/master/docs/api.md#functionname-options-function---this (SQLite doesn't support stored procedures, and node-sqlite3 doesn't allow user defined SQL functions either, only binary extensions)
TL;DR IN param - akin to an argument passed by value in most languages (think string/number/bigint/boolean in JS). You get a copy of what is outside. |
Is your feature request related to a problem? Please describe.
In some cases, it may be appropriate to define functionality in stored procedures or functions, particularly in otherwise chatty series of queries that don't need additional input by the app, beyond the initial one. In PostgreSQL, there's also the fact that stored functions are what's needed to be attached to triggers.
Describe the solution you'd like
I'm thinking something along the lines of
and then when calling
And of course, it goes without saying that eventually, the schema generator and entity generator should be able to handle those definitions, so that these can be versioned along with the rest of the DB.
Describe alternatives you've considered
The way to use those right now is to define them manually, perhaps in separately maintained and versioned SQL files, and use raw queries to manually map the results back. Extremely inconvenient, which means most people would rather never use them, even if appropriate.
Additional context
Related to #5053
EDIT:
Param
decorator removed, per feedback. Replaced withpersist: false
for OUT params, while refs by default would be INOUT params.The text was updated successfully, but these errors were encountered: