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

Automatically Generate Types from Database queries #39

Closed
4 tasks
ForbesLindesay opened this issue Sep 28, 2019 · 2 comments
Closed
4 tasks

Automatically Generate Types from Database queries #39

ForbesLindesay opened this issue Sep 28, 2019 · 2 comments
Assignees
Labels
enhancement New feature or request wontfix This will not be worked on

Comments

@ForbesLindesay
Copy link
Owner

I would like to be able to automatically generate types from the database queries. To do this:

  • Build an SQL parser that is flexible in how it handles placeholders that could be replaced with other SQL, and which supports a reasonable subset of the postgres/mysql/sqlite syntax - being worked on in feat: create an SQL parser #20
  • Write util to extract queries from typescript files
  • Write util to extract type from parsed SQL query and database schema
  • Tie everything together in an awesome CLI
@ForbesLindesay ForbesLindesay self-assigned this Sep 28, 2019
@stevenmiller888
Copy link

Re the SQL parser - ideally it supports the entire grammar for each dialect. I built https://github.com/stevenmiller888/ts-mysql-parser for the language service plugin, on top of Antlr4 with the grammar extracted from MySQL workbench. The beauty of it is that you can specify the version you want. Working with Antlr4 was a pretty pleasant experience btw, and it looks like they have a full grammar ready-to-go for sqlite.

Re extracting types - not sure exactly what you mean but maybe this is related: https://github.com/nettofarah/mysql-schema-ts.

@ForbesLindesay ForbesLindesay added enhancement New feature or request wontfix This will not be worked on labels Feb 15, 2022
@ForbesLindesay
Copy link
Owner Author

The pg-typed/mysql-typed approach seems to have worked well enough here to cover 99% of the use case. I no longer think it's a worthwhile idea right now to attempt to generate types from raw SQL queries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants