Optimize parse constraint (#4153)
* for Config.cacheStore store PreparedStmtDB key * invalid db error and value and invalid value length error (#4151) * support named params in Select API (#4142) * adds support for named arguments in select * changes clause identifies and adds test * optimize match english letters and midline Co-authored-by: Ratan Phayade <ratanphayade@users.noreply.github.com>
This commit is contained in:
parent
221d0a0ec1
commit
02cb40531e
@ -6,8 +6,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// match English letters and midline
|
// reg match english letters and midline
|
||||||
regEnLetterAndmidline = regexp.MustCompile("^[A-Za-z-_]+$")
|
regEnLetterAndMidline = regexp.MustCompile("^[A-Za-z-_]+$")
|
||||||
)
|
)
|
||||||
|
|
||||||
type Check struct {
|
type Check struct {
|
||||||
@ -22,7 +22,7 @@ func (schema *Schema) ParseCheckConstraints() map[string]Check {
|
|||||||
for _, field := range schema.FieldsByDBName {
|
for _, field := range schema.FieldsByDBName {
|
||||||
if chk := field.TagSettings["CHECK"]; chk != "" {
|
if chk := field.TagSettings["CHECK"]; chk != "" {
|
||||||
names := strings.Split(chk, ",")
|
names := strings.Split(chk, ",")
|
||||||
if len(names) > 1 && regEnLetterAndmidline.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}
|
checks[names[0]] = Check{Name: names[0], Constraint: strings.Join(names[1:], ","), Field: field}
|
||||||
} else {
|
} else {
|
||||||
if names[0] == "" {
|
if names[0] == "" {
|
||||||
|
@ -3,7 +3,6 @@ package schema
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jinzhu/inflection"
|
"github.com/jinzhu/inflection"
|
||||||
@ -536,7 +535,11 @@ func (rel *Relationship) ParseConstraint() *Constraint {
|
|||||||
settings = ParseTagSetting(str, ",")
|
settings = ParseTagSetting(str, ",")
|
||||||
)
|
)
|
||||||
|
|
||||||
if idx != -1 && regexp.MustCompile("^[A-Za-z-_]+$").MatchString(str[0:idx]) {
|
// optimize match english letters and midline
|
||||||
|
// The following code is basically called in for.
|
||||||
|
// In order to avoid the performance problems caused by repeated compilation of regular expressions,
|
||||||
|
// it only needs to be done once outside, so optimization is done here.
|
||||||
|
if idx != -1 && regEnLetterAndMidline.MatchString(str[0:idx]) {
|
||||||
name = str[0:idx]
|
name = str[0:idx]
|
||||||
} else {
|
} else {
|
||||||
name = rel.Schema.namer.RelationshipFKName(*rel)
|
name = rel.Schema.namer.RelationshipFKName(*rel)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user