mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-10 16:30:01 +08:00
Generate caches that support custom key prefix. (#4643)
This commit is contained in:
@@ -30,6 +30,7 @@ type (
|
||||
cfg *config.Config
|
||||
isPostgreSql bool
|
||||
ignoreColumns []string
|
||||
prefix string
|
||||
}
|
||||
|
||||
// Option defines a function with argument defaultGenerator
|
||||
@@ -56,7 +57,7 @@ type (
|
||||
)
|
||||
|
||||
// NewDefaultGenerator creates an instance for defaultGenerator
|
||||
func NewDefaultGenerator(dir string, cfg *config.Config, opt ...Option) (*defaultGenerator, error) {
|
||||
func NewDefaultGenerator(prefix, dir string, cfg *config.Config, opt ...Option) (*defaultGenerator, error) {
|
||||
if dir == "" {
|
||||
dir = pwd
|
||||
}
|
||||
@@ -72,7 +73,7 @@ func NewDefaultGenerator(dir string, cfg *config.Config, opt ...Option) (*defaul
|
||||
return nil, err
|
||||
}
|
||||
|
||||
generator := &defaultGenerator{dir: dir, cfg: cfg, pkg: pkg}
|
||||
generator := &defaultGenerator{dir: dir, cfg: cfg, pkg: pkg, prefix: prefix}
|
||||
var optionList []Option
|
||||
optionList = append(optionList, newDefaultOption())
|
||||
optionList = append(optionList, opt...)
|
||||
@@ -260,7 +261,7 @@ func (g *defaultGenerator) genModel(in parser.Table, withCache bool) (string, er
|
||||
return "", fmt.Errorf("table %s: missing primary key", in.Name.Source())
|
||||
}
|
||||
|
||||
primaryKey, uniqueKey := genCacheKeys(in)
|
||||
primaryKey, uniqueKey := genCacheKeys(g.prefix, in)
|
||||
|
||||
var table Table
|
||||
table.Table = in
|
||||
|
||||
Reference in New Issue
Block a user