-
-
Notifications
You must be signed in to change notification settings - Fork 65
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
Generating a types for function #82
Comments
I am considering this myself. I am trying to move some essential parts of business logic into the database and I would love for my code base for deal with that easily. Currently, I am bothered that views lose the knowledge of indices. I will try and look into your request after that. |
Splendid! |
I should have time to attempt this in the next couple weeks. I need this to finish off typing the features I use currently. |
I haven't had time to finish a prototype for this item yet but I did find a few concerns while working on one. As far as I can tell there isn't a way to indicate nullability (just is-optional) in PG function arguments which would lead to less than ideal types in TS. My current idea would be to add an option to the config to control default nullability (name: COMMENT ON FUNCTION some_function IS
E'This function does something.
@arg:foo @type:Foo @nullable
@arg:bar @non-nullable
@returns @type:Bar @non-nullable
'; I plan to parse this by checking if in the first tag on a line is one of If there isn't an I haven't had a reason to use variadic function args in PG so far so I'm not sure if there are pitfalls for typing those yet. @kristiandupont Any feedback on the above approach? |
So I've implemented a very lightweight view column inference in I don't know if PG exposes sufficient information to do this. If not, then your approach is probably the way to go. I am wondering though if we could lean more on some existing syntax, either JSDoc or maybe Typescript ( |
As far as I can tell Postgres provides no way to directly add comments to function arguments : ( From what I recall when I first started transitioning from JSDoc to TS they have some tricky edge cases where they don't map nicely. Sticking to just typescript seems cleaner. TS in. TS out. The Suggesting a hybrid approach, we use // define the whole function signature
@signature:(foo:Foo | null, bar) => Bar\n
//^ tag \___to typescript parser___/
// longer tag name for documentation clarity? must be one tag per line
@argument: foo?: Foo | null\n
//^ tag \_to typescript_/ Pass contents into TS lexer/parser and use AST to determine types, hopefully
// shorthand. must still be one tag per line if not using signature
@arg:foo?:Foo|null\n I haven't worked with typescripts parser yet but as long as it passes back a sensible AST this should be manageable. I'll work on just handling the |
Is it possible also to add option, to extract types for postgres functions?
function name, parameters types and return types ?
The text was updated successfully, but these errors were encountered: