2023-11-14 16:07:41 +02:00
|
|
|
The crud_generator application is designed to automatically generate source code files
|
|
|
|
in golang language to perform CRUD operations.
|
2023-11-22 16:19:22 +02:00
|
|
|
A completely ready-made microservice is created that can be launched immediately.
|
2023-11-14 16:07:41 +02:00
|
|
|
|
2024-08-21 16:30:55 +02:00
|
|
|
For each table in the Postgres SQL database, functions will be automatic created to perform crud operations:
|
|
|
|
- Create()
|
|
|
|
- Read()
|
|
|
|
- Update()
|
|
|
|
- Delete() (or Delete() + Restore(), if there is an is_deleted field)
|
|
|
|
- Save() - creating a new record when ID is empty, or updating a record when ID is not empty
|
2024-03-15 15:30:07 +02:00
|
|
|
- ReadFromCache() - reading from cache or database
|
|
|
|
- Update_ColumnName() - changing only one column with the name ColumnName,
|
|
|
|
separate function for each column of each table
|
2024-08-21 16:30:55 +02:00
|
|
|
- UpdateManyFields() - change several columns listed in an array
|
|
|
|
- FindBy_ColumnName() - search for a record by one or more columns (if you fill in the findby_functions.json file)
|
|
|
|
- FindMassBy_ColumnName() - search for multiple records by one or more columns (if you fill in the findmassby_functions.json file)
|
2024-09-18 13:25:47 +02:00
|
|
|
- ReadAll() - returns all table records, except those marked for deletion is_deleted=true (if you fill in the readall_functions.json file)
|
2024-03-15 15:30:07 +02:00
|
|
|
|
2023-11-14 16:07:41 +02:00
|
|
|
files are generated:
|
2023-11-22 16:19:22 +02:00
|
|
|
1. table - struct structure with all fields from the database, and gorm + json annotations
|
2024-08-21 16:30:55 +02:00
|
|
|
Tables with fields in the database must be created manually in advance.
|
|
|
|
The code generator will find all the tables and their fields in the database and use them.
|
|
|
|
|
|
|
|
2. entities - struct structure, including table, with crud operations functions
|
|
|
|
|
|
|
|
3. crud - files for performing crud operations, exchange with the database,
|
|
|
|
as well as files with tests
|
|
|
|
|
|
|
|
4. grpc server - files for performing crud operations over the network, using the GRPC protocol,
|
|
|
|
as well as files with tests
|
|
|
|
|
|
|
|
5. grpc client - client files for using GRPC by third-party services,
|
|
|
|
as well as files with tests
|
|
|
|
|
|
|
|
6. nrpc server - files for performing crud operations over the network, using the NRPC protocol (via the NATS message broker),
|
|
|
|
as well as files with tests
|
|
|
|
|
|
|
|
7. nrpc client - client files for use by NRPC third-party services,
|
|
|
|
as well as files with tests
|
|
|
|
|
|
|
|
8. crud_starter - a file with functions for switching to the desired protocol db or grpc or nrpc
|
|
|
|
|
|
|
|
9. main.go and other .go files
|
|
|
|
|
|
|
|
10. Makefile - script launch configuration file
|
|
|
|
|
|
|
|
11. .env - file for filling in the microservice configuration (database connection parameters, etc.)
|
2023-11-22 16:19:22 +02:00
|
|
|
|
2023-11-14 16:07:41 +02:00
|
|
|
|
|
|
|
Code templates are stored in the bin/templates folder.
|
|
|
|
The code template is a .go file copied from the real project -
|
|
|
|
so it’s easy to make a template (change it to your own) - just copy your file.
|
|
|
|
The code generator replaces part of the code in the template with another code:
|
|
|
|
- name of the database table
|
|
|
|
- model name
|
|
|
|
- adding and removing imports
|
|
|
|
|
|
|
|
Installation procedure:
|
|
|
|
1. Compile this repository
|
2024-03-15 10:42:48 +02:00
|
|
|
>make build
|
|
|
|
>
|
2023-11-14 16:07:41 +02:00
|
|
|
the crud_generator file will appear in the bin folder
|
|
|
|
|
2023-11-22 16:19:22 +02:00
|
|
|
2. Fill in the settings in the file bin/templates/configs_/settings.txt
|
2023-11-14 16:07:41 +02:00
|
|
|
- connections to your database
|
2023-11-22 16:19:22 +02:00
|
|
|
- the name of your new service
|
2023-11-14 16:07:41 +02:00
|
|
|
- URL of your new service
|
|
|
|
- and etc.
|
|
|
|
|
2024-03-15 15:30:07 +02:00
|
|
|
3. Tables in the database must be created in advance, manually.
|
|
|
|
|
|
|
|
4. Launch crud_generator
|
2023-11-14 16:07:41 +02:00
|
|
|
A new folder with the name of your service will appear in the bin folder,
|
|
|
|
with subfolders and finished files inside.
|
|
|
|
|
2024-03-15 15:30:07 +02:00
|
|
|
5. Fill in the configuration parameters in the .env file
|
2023-11-22 16:19:22 +02:00
|
|
|
Start microservice:
|
2024-03-15 15:43:40 +02:00
|
|
|
>make run
|
|
|
|
>
|
2023-11-22 16:19:22 +02:00
|
|
|
|
2024-10-24 14:45:53 +02:00
|
|
|
Features:
|
|
|
|
1. Tables with a prefix in the name or comments = "DELETED" or "УДАЛИТЬ" are ignored
|
|
|
|
2. Columns with a prefix in the name or comments = "DELETED" or "УДАЛИТЬ" are ignored
|
2023-11-14 16:07:41 +02:00
|
|
|
|
|
|
|
P.S.
|
2024-08-21 16:30:55 +02:00
|
|
|
I generated myself 420,000 lines of code, from 70 tables in the database, for my service.
|
2023-11-14 16:07:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
Source code in Golang language.
|
|
|
|
Tested on Linux Ubuntu
|
|
|
|
Readme from 11/14/2023
|
|
|
|
|
2024-06-10 14:46:44 +02:00
|
|
|
![modules](https://github.com/ManyakRus/crud_generator/assets/30662875/304a41fa-a84c-40c4-9566-e5d65a381175)
|
|
|
|
|
|
|
|
|
2023-11-14 16:07:41 +02:00
|
|
|
Made by Alexander Nikitin
|
2024-03-15 10:42:48 +02:00
|
|
|
https://github.com/ManyakRus/crud_generator
|