gorm gen使用


gorm gen使用

1.安裝

git clone github.com/olongfen/gormgen

cd cmd/gormgen/

go build -o gormgen main.go

mv gormgen /usr/local/bin/

2.使用
在結構體模型加對應的注解,//go:generate

// 用戶Demo表
//go:generate gormgen -structs User -output user_gen.go
type User struct {
    Id        int32     // 主鍵
    UserName  string    // 用戶名
    NickName  string    // 昵稱
    Mobile    string    // 手機號
    IsDeleted int32     // 是否刪除 1:是  -1:否
    CreatedAt time.Time `gorm:"time"` // 創建時間
    UpdatedAt time.Time `gorm:"time"` // 更新時間
}

3.執行生成命令

go generate ./...

相關鏈接

https://my.oschina.net/olongfen/blog/4676482
github.com/MohamedBassem/gormgen
https://segmentfault.com/a/1190000039300764
http://www.systonsoft.com/article/237686.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM