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

Code generation from database schema #58

Open
martonmiklos opened this issue Dec 31, 2019 · 3 comments
Open

Code generation from database schema #58

martonmiklos opened this issue Dec 31, 2019 · 3 comments
Projects

Comments

@martonmiklos
Copy link
Contributor

Hi @HamedMasafi

First of all thank you for your great work, I am not using it yet, but it looks very promising!

I was wondering if it would be useful to create a code generator which would generate the database/table code automatically from a given database schema.

I am thinking about something similar what is called scaffolding in CakePHP (more exactly only the model generation of that).

The table connections (hasMany, belongsTo in CakePHP terminology) could be detected by detecting the naming convention of the fields (if post table has an user_id key then post belongsTo User).

If you like this idea I can work on it and submit a PR or we can develop this tool even in a separate repository.

Thanks in advance and happy new year!

@martonmiklos
Copy link
Contributor Author

@HamedMasafi FYI I have put together a tool which is capable of generating the Nut ORM classes from a MySQL schema:
https://github.com/martonmiklos/nut_codegen

I am still polishing it, at the moment it generates code which compiles. It is just a heads up, it is still rough (no test for e.g.) but I think if it would be extended to the non MySQL databases then it would add a lot to the Nut's traits.

@HamedMasafi
Copy link
Owner

Hi @martonmiklos
I'm so sorry for the late reply
It sounds like a good idea, and I agree with it. But there are a few points
First, I have a list of things that have not been done for the nut and I have no idea what to add to the list at the moment, but I will help if you want to.
It is up to you to decide whether to add a nut or to have a separate project. But if it ever produced the right output project for the nut I'd be happy to pr

I also saw your new project

But I also have one suggestion: Make this project part of a nut. In fact, a class like SchemaGenerator creates a Nut :: DatabaseModel from a database. He can then be added to the CodeGenerator class and provided with the library for a code generation tool. If you agree with the idea, we can do it

@martonmiklos
Copy link
Contributor Author

Hi @HamedMasafi
Thank you for your reply, and it was not late at all!

I am still on the steep phase of the learning curve with Nut, but I am starting to discover it's capabilities.

I am glad that you would like to see that you are open for merging it to the Nut. I will work on integrating it to the Nut: I will create some CI tests before submitting PR.

What I see now in general that the Nut wants to generate the tables from the code, what might be useful to make disable-able in the case of autogenerated database/table classes.

@HamedMasafi HamedMasafi added this to Planned in Nut Feb 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Nut
  
Planned
Development

No branches or pull requests

2 participants