Skip to content

Commit abd38dd

Browse files
daheigemittwillson
authored andcommitted
optimization check for ParseCheckConstraints (go-gorm#4063)
1 parent df58a0d commit abd38dd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

schema/check.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import (
55
"strings"
66
)
77

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

0 commit comments

Comments
 (0)