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

Generate structs of database views #52

Open
erojano opened this issue May 25, 2023 · 5 comments
Open

Generate structs of database views #52

erojano opened this issue May 25, 2023 · 5 comments

Comments

@erojano
Copy link

erojano commented May 25, 2023

This is a kind feature request :)

Is there any way of generate structs also of database views?

Thank you.

@fraenky8
Copy link
Owner

Hi @erojano!

Yes this is a good one and makes sense to me, I'm totally in for that! Do you want to give it a try? I'm not sure if I can find time for adding this in near future.

@erojano
Copy link
Author

erojano commented Jun 1, 2023

Yeah, I'll be happy to contribute; I just have to make some time.
I think tables-to-go is a "must have"; this is big. 💪🏼

@mpkondrashin
Copy link

Need it too! Will it be implemented?

@fraenky8
Copy link
Owner

fraenky8 commented Oct 28, 2023

I'm afraid it is not as easy as it looks like. At least for MySQL I checked real quick on how to get the column definitions and it seems all we can get here is the CREATE statement the view was created with - https://dev.mysql.com/doc/refman/8.0/en/information-schema-views-table.html

Same applies for PG: https://www.postgresql.org/docs/current/view-pg-views.html

It seems it boils down to be the same request as in #1 - parsing a SELECT-query string to create the table&column definitions from it rather than querying INFORMATION_SCHEMA tables. This would require a sophisticated SQL parser
library (per database?) and much more time to integrate & implement this feature.

I'm open to discuss the options, but not sure if I can find time to actively implement it.

@mpkondrashin
Copy link

I need this kind of feature for my other project, so I have created https://github.com/mpkondrashin/views and used it to generate https://github.com/mpkondrashin/smsdb this code is not fully tested, it is PoC, I would say, but it shows that generating go structures for MySQL views is possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants