From 2a1463811ee1dc85d168fd639a2d4251d030e6e5 Mon Sep 17 00:00:00 2001 From: Ivan Valkov Date: Mon, 3 Jul 2017 14:49:54 +0100 Subject: [PATCH] Allow use number as column name (#1517) * Updated scope.go to always quote when adding index I am using numbers for column names (to be compatible with protobuf) and adding unique index to them does not work since they are not quoted. I do not see a reason to check if the column name is a string in order to quote it. Correct me if I am wrong. * Updated the columnRegexp to include decimals * Update scope.go --- scope.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scope.go b/scope.go index 9a237998..4fcb84c1 100644 --- a/scope.go +++ b/scope.go @@ -448,8 +448,8 @@ func (scope *Scope) callMethod(methodName string, reflectValue reflect.Value) { } var ( - columnRegexp = regexp.MustCompile("^[a-zA-Z]+(\\.[a-zA-Z]+)*$") // only match string like `name`, `users.name` - isNumberRegexp = regexp.MustCompile("^\\s*\\d+\\s*$") // match if string is number + columnRegexp = regexp.MustCompile("^[a-zA-Z\\d]+(\\.[a-zA-Z\\d]+)*$") // only match string like `name`, `users.name` + isNumberRegexp = regexp.MustCompile("^\\s*\\d+\\s*$") // match if string is number comparisonRegexp = regexp.MustCompile("(?i) (=|<>|>|<|LIKE|IS|IN) ") countingQueryRegexp = regexp.MustCompile("(?i)^count(.+)$") )