Nut icon indicating copy to clipboard operation
Nut copied to clipboard

Code generation from database schema

Open martonmiklos opened this issue 4 years ago • 3 comments

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 avatar Dec 31 '19 12:12 martonmiklos

@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.

martonmiklos avatar Jan 03 '20 21:01 martonmiklos

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

HamedMasafi avatar Jan 04 '20 11:01 HamedMasafi

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.

martonmiklos avatar Jan 05 '20 12:01 martonmiklos