Skip to content

shaozi17/gorm-zero

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gorm-zero

go zero gorm extension

If you use go zero, and you want to use Gorm. You can use this library.

Usage

  • add the dependent
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

About

go zero gorm extension / Integrated processing of db model and Redis cache

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%