2025-10-27 11:05:03 +08:00
..
2025-10-16 13:28:24 +08:00
2025-10-27 11:05:03 +08:00

自动生成数据库模型和常见的 CRUD 操作

Usage

go run cmd/gormgen/main.go -h

Usage of ./cmd/gormgen/main.go:
  -dsn string
        consult[https://gorm.io/docs/connecting_to_the_database.html]
  -tables string
        enter the required data table or leave it blank

-dsn

用于连接数据库的DSN reference: https://gorm.io/docs/connecting_to_the_database.html

-tables

指定要生成的表名称,默认所有表。

eg :

--tables="orders"       # generate from `orders`

--tables="orders,users" # generate from `orders` and `users`

--tables=""             # generate from all tables

示例

# 根目录下执行
go run cmd/gormgen/main.go -dsn "root:api2api..@tcp(sh-cynosdbmysql-grp-88th45wy.sql.tencentcdb.com:28555)/mini_chat?charset=utf8mb4&parseTime=True&loc=Local" -tables "log_operation,log_request,admin,app_keyword,app_keyword_reply,app_user,app_message_log,mini_program,mini_program_access_token"