First, after downloading the demo project, we will use the user's model to demonstrate the code generation.
Model is a bridge for services to access the persistent data layer. The persistent data of the business often exists in databases such as mysql and mongo. We all know that the operation of a database is nothing more than CURD. And these tasks will also take up part of the time for development. I once wrote 40 model files when writing a business. According to the complexity of different business requirements, on average, each model file is almost required. 10 minutes, for 40 files, 400 minutes of working time, almost a day's workload, and the goctl tool can complete the 400 minutes of work in 10 seconds.
Enter the demo project
book, find the
user.sql file under
user/model, and execute the table creation in your own database.
service/user/model directory and execute the command
$datasource is the database connection address
In Goland, right-click
user.sql, enter and click
Model Code to generate it, or open the
Enter the editing area, use the shortcut key
Command+N (for macOS) or
alt+insert (for windows), select
The intellij plug-in generation needs to install the goctl plug-in, see intellij plugin for details
For persisting data, if more flexible database capabilities are required, including transactional capabilities, see Mysql
For distributed transaction capabilities, see distributed-transaction.md