Skip to content

Commit b881483

Browse files
authored
Rename IsValidDBNameChar to IsInvalidDBNameChar (#7582)
1 parent b289563 commit b881483

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

chainable_api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func (db *DB) Omit(columns ...string) (tx *DB) {
178178
tx = db.getInstance()
179179

180180
if len(columns) == 1 && strings.ContainsRune(columns[0], ',') {
181-
tx.Statement.Omits = strings.FieldsFunc(columns[0], utils.IsValidDBNameChar)
181+
tx.Statement.Omits = strings.FieldsFunc(columns[0], utils.IsInvalidDBNameChar)
182182
} else {
183183
tx.Statement.Omits = columns
184184
}
@@ -283,7 +283,7 @@ func joins(db *DB, joinType clause.JoinType, query string, args ...interface{})
283283
func (db *DB) Group(name string) (tx *DB) {
284284
tx = db.getInstance()
285285

286-
fields := strings.FieldsFunc(name, utils.IsValidDBNameChar)
286+
fields := strings.FieldsFunc(name, utils.IsInvalidDBNameChar)
287287
tx.Statement.AddClause(clause.GroupBy{
288288
Columns: []clause.Column{{Name: name, Raw: len(fields) != 1}},
289289
})

finisher_api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ func (db *DB) Count(count *int64) (tx *DB) {
465465

466466
if len(tx.Statement.Selects) == 1 {
467467
dbName := tx.Statement.Selects[0]
468-
fields := strings.FieldsFunc(dbName, utils.IsValidDBNameChar)
468+
fields := strings.FieldsFunc(dbName, utils.IsInvalidDBNameChar)
469469
if len(fields) == 1 || (len(fields) == 3 && (strings.ToUpper(fields[1]) == "AS" || fields[1] == ".")) {
470470
if tx.Statement.Parse(tx.Statement.Model) == nil {
471471
if f := tx.Statement.Schema.LookUpField(dbName); f != nil {
@@ -564,7 +564,7 @@ func (db *DB) Pluck(column string, dest interface{}) (tx *DB) {
564564
}
565565

566566
if len(tx.Statement.Selects) != 1 {
567-
fields := strings.FieldsFunc(column, utils.IsValidDBNameChar)
567+
fields := strings.FieldsFunc(column, utils.IsInvalidDBNameChar)
568568
tx.Statement.AddClauseIfNotExists(clause.Select{
569569
Distinct: tx.Statement.Distinct,
570570
Columns: []clause.Column{{Name: column, Raw: len(fields) != 1}},

utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func FileWithLineNum() string {
4848
return ""
4949
}
5050

51-
func IsValidDBNameChar(c rune) bool {
51+
func IsInvalidDBNameChar(c rune) bool {
5252
return !unicode.IsLetter(c) && !unicode.IsNumber(c) && c != '.' && c != '*' && c != '_' && c != '$' && c != '@'
5353
}
5454

utils/utils_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"time"
1111
)
1212

13-
func TestIsValidDBNameChar(t *testing.T) {
13+
func TestIsInvalidDBNameChar(t *testing.T) {
1414
for _, db := range []string{"db", "dbName", "db_name", "db1", "1dbname", "db$name"} {
15-
if fields := strings.FieldsFunc(db, IsValidDBNameChar); len(fields) != 1 {
15+
if fields := strings.FieldsFunc(db, IsInvalidDBNameChar); len(fields) != 1 {
1616
t.Fatalf("failed to parse db name %v", db)
1717
}
1818
}

0 commit comments

Comments
 (0)