Skip to content
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

Refactoring ExternArgs -> SQL gen for type safety #690

Open
workingjubilee opened this issue Sep 14, 2022 · 0 comments
Open

Refactoring ExternArgs -> SQL gen for type safety #690

workingjubilee opened this issue Sep 14, 2022 · 0 comments
Labels
enhancement New feature or request refactor Changes would be considered a refactor of existing functionality. sql-gen

Comments

@workingjubilee
Copy link
Member

workingjubilee commented Sep 14, 2022

As noted during discussion in #683, there's currently situations where we are using purely programmatic logic with vectors of enums rather than type-driven logic, when types are fairly good at encoding logical invariants. This results in errors like the one mentioned in #640, unfortunately.

I believe we should start with tokenizing the ExternArgs more or less read off "as-is", and then use them to build struct CreateFn or similar that can only fmt::Display into a valid SQL statement. By taking in the ExternArgs "directly", and only verifying they are valid arguments in the first step, we effectively "lex" them, and then parse them in a separate step that will discern if the combined arguments can logically parse into a correct SQL statement. This is good compiler design (and PGX is more and more that: a compiler) and allows distinguishing between individually invalid and combined invalid inputs, providing more precise and useful error messages.

@workingjubilee workingjubilee added enhancement New feature or request sql-gen refactor Changes would be considered a refactor of existing functionality. labels Sep 14, 2022
@workingjubilee workingjubilee changed the title Refactoring ExternArgs -> DDL gen for type safety Refactoring ExternArgs -> SQL gen for type safety Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactor Changes would be considered a refactor of existing functionality. sql-gen
Projects
None yet
Development

No branches or pull requests

1 participant