Generate models from template files #165
dominiks96
started this conversation in
Ideas
Replies: 2 comments
-
@go-jet Could you check this out? I think it's a nice idea and I'm happy to contribue if you could point me to some direction. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi @dominikschopf .
Does it mean you use only one database for development, staging, and production?
It can be solved using docker. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The idea
I'd like to be able to have some kind of templating language, containing the definition of my tables / views and generate my models from there.
The templating file could be some kind of json / yml or something similar.
Why?
Generation of the models as part of the build process
Now
As far as I understand, generating the model is now considered as part of the actual development. The developer is supposed to create a database connection, generate the models and push them into the VCS.
Some CI system could then pick them up to build the acual Go binary.
Then
The template file is going to be part of the code base and therefore generation of the actual models can be part of the build process.
This gives the advantage of not having "some kind of compiled class" in the VCS.
I know this defeats the point of the "typesafety" against the database. However, in a real life the models are part of the VCS and are merged together "in the master branch". If someone touches the database after the merge was done, the runtime is simply gonna fail anyways.
Accessing only parts of the database
For now, every Go microservice I have, which access the database, has a complete representation of a massive database.
However, the service actually only access a hand full of tables or views.
Using the templating files, I could easily define tables or even packages of tables in certain modules.
Each microservice can reference the modules he needs.
Easier generation for the developer
In my case, developers is quite far away from the actual running database. Setting one up "locally" is not so easy, because there are shell scripts doing this - some devs are on windows, some are on macOS and whatever.
Right now, everyone has to install jet on a remote machine, from where he can then access the (shared!) database and generate models from there - then copy them to his local. This is pain.
Beta Was this translation helpful? Give feedback.
All reactions