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

Specify table(s) and generated filename #56

Open
guhkun13 opened this issue Sep 2, 2023 · 7 comments
Open

Specify table(s) and generated filename #56

guhkun13 opened this issue Sep 2, 2023 · 7 comments
Assignees

Comments

@guhkun13
Copy link

guhkun13 commented Sep 2, 2023

Hi, thanks for great repo.

I wonder if it is possible if we can specify which table(s) that we'll be convert into struct.
maybe using flag table ?
and also option to define the generated filename, such as model.go

example 1: tables-to-go -d booking_app -table invoice -of /internal/domain/invoice -o model
--> will create file /internal/domain/invoice/model.go

example 2: tables-to-go -d booking_app -table order -of /internal/domain/order -o model
--> will create file /internal/domain/order/model.go

I think this would allow us to be more selective on generating the struct and saving it into each domain folder with specified filename.

@guhkun13 guhkun13 changed the title Specify single/multiple table Specify table(s) and generated filename Sep 2, 2023
@fraenky8
Copy link
Owner

fraenky8 commented Sep 4, 2023

Hi!

I like the idea to filter by tables via (multiple) -table flags 👍

For the file name we need to decide what behavior we want:

  1. If multiple tables are specified then also multiple file-names (in same order) needs to be specified?
  2. Or we restrict the usage of only one -table flag and one -o flag at the same time?
  3. ???

Tbh I would like to keep the scope of the tool small, don't make it more complex as it is already. We can start on the -table flag first before moving on to the file-name output? Because I think these are 2 different new features.

@blackfyre
Copy link

Hey 😄

My 2 cents: I'm fine with the filtering only and with keeping the existing rules around filenames

@fraenky8
Copy link
Owner

fraenky8 commented Oct 14, 2024

Hey guys!

I decided to split this issue into two parts:

  1. Add the -table flag to filter for specific tables:

Please checkout PR #60 and give it a try. The new -table flag is applied on SQL level to filter for the table names. If everything looks good, will merge 👍 LMK!

  1. Add support for the -of flag to accept a filename in addition to the a path.

I have multiple ideas on this: First, if a file-name is given (rule will be likely *.go file) - then only one -table flag has to be given. But thinking about it further, maybe we can provide a placeholder in the path like %s which gets substituted by the table names in the order specified and hence, different directories but same file name will be possible:

tables-to-go -d booking_app -table invoice,order -of /internal/domain/%s/model.go

Will produce:

/internal/domain/invoice/model.go
/internal/domain/order/model.go

If there is no placeholder but a file-ending given in -of then the CLI will error.

Another approach would be to support multiple -of flags as well which apply in same order as the table flag.

LMK WDYT

@blackfyre
Copy link

@fraenky8

Thanks for taking this up! I really like the approach!
Albeit there's 1 problem 😅
I wasn't able to make it work... I've downloaded the repo, switched over to the PR branch, built it, added the -table flag with a comma separated list of table names but it still dumps all the table in the DB.
The mysql 5.7 DB I'm working on contains 200+ tables with varied naming conventions (snake, camel, you name it...) applied to the table names.

@fraenky8
Copy link
Owner

OMG I was so focused to add the new flag and integrate it into the SQL query that I forgot to actually pass it down 🤦‍♂️

@blackfyre I added one more commit, please update your local branch, run make install and try again! I tested on my side and it seems to work 🤞

@blackfyre
Copy link

Can confirm, it's working 👍

@fraenky8
Copy link
Owner

Awesome, glad to hear! I will test with other databases later this week and if everything appears to be good, will merge into master 👍

@fraenky8 fraenky8 linked a pull request Oct 16, 2024 that will close this issue
@fraenky8 fraenky8 removed a link to a pull request Oct 16, 2024
@fraenky8 fraenky8 self-assigned this Oct 16, 2024
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