gorm-zero

module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2023 License: MIT

README

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL