gorm-zero
go zero gorm extension
If you use go zero, and you want to use Gorm. You can use this library.
Usage
go get github.com/shaozi17/gorm-zero
- replace template/model in your project with gorm-zero/template/{goctl version}/model
- generate
goctl model mysql -src={patterns} -dir={dir} -cache --home ./template
Mysql
Config
type Config struct {
Mysql gormc.Mysql
...
}
Initialization
func NewServiceContext(c config.Config) *ServiceContext {
db, err := gormc.ConnectMysql(c.Mysql)
if err != nil {
log.Fatal(err)
}
...
}
PgSql
Config
type Config struct {
PgSql gormc.PgSql
...
}
Initialization
func NewServiceContext(c config.Config) *ServiceContext {
db, err := gormc.ConnectPgSql(c.PgSql)
if err != nil {
log.Fatal(err)
}
...
}
Usage Example