Generate caches that support custom key prefix. (#4643)

This commit is contained in:
kesonan
2025-02-12 23:31:30 +08:00
committed by GitHub
parent 48d0709ca6
commit 7a4818da59
9 changed files with 60 additions and 45 deletions

View File

@@ -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