optimization check for ParseCheckConstraints (#4063)

This commit is contained in:
heige 2021-02-07 10:12:13 +08:00 committed by GitHub
parent ef5ef18d4a
commit e80853e7f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -5,6 +5,11 @@ import (
"strings"
)
var (
// match English letters and midline
regEnLetterAndmidline = regexp.MustCompile("^[A-Za-z-_]+$")
)
type Check struct {
Name string
Constraint string // length(phone) >= 10
@ -17,7 +22,7 @@ func (schema *Schema) ParseCheckConstraints() map[string]Check {
for _, field := range schema.FieldsByDBName {
if chk := field.TagSettings["CHECK"]; chk != "" {
names := strings.Split(chk, ",")
if len(names) > 1 && regexp.MustCompile("^[A-Za-z-_]+$").MatchString(names[0]) {
if len(names) > 1 && regEnLetterAndmidline.MatchString(names[0]) {
checks[names[0]] = Check{Name: names[0], Constraint: strings.Join(names[1:], ","), Field: field}
} else {
if names[0] == "" {