diff --git a/main.go b/main.go index 67e5f58e5..eac28f8ab 100644 --- a/main.go +++ b/main.go @@ -209,8 +209,8 @@ func (s *DB) NewScope(value interface{}) *Scope { return scope } -// QueryExpr returns the query as expr object -func (s *DB) QueryExpr() *expr { +// QueryExpr returns the query as SqlExpr object +func (s *DB) QueryExpr() *SqlExpr { scope := s.NewScope(s.Value) scope.InstanceSet("skip_bindvar", true) scope.prepareQuerySQL() @@ -219,7 +219,7 @@ func (s *DB) QueryExpr() *expr { } // SubQuery returns the query as sub query -func (s *DB) SubQuery() *expr { +func (s *DB) SubQuery() *SqlExpr { scope := s.NewScope(s.Value) scope.InstanceSet("skip_bindvar", true) scope.prepareQuerySQL() diff --git a/scope.go b/scope.go index e64a8ba8e..eb7525b88 100644 --- a/scope.go +++ b/scope.go @@ -257,7 +257,7 @@ func (scope *Scope) CallMethod(methodName string) { func (scope *Scope) AddToVars(value interface{}) string { _, skipBindVar := scope.InstanceGet("skip_bindvar") - if expr, ok := value.(*expr); ok { + if expr, ok := value.(*SqlExpr); ok { exp := expr.expr for _, arg := range expr.args { if skipBindVar { @@ -785,7 +785,7 @@ func (scope *Scope) orderSQL() string { for _, order := range scope.Search.orders { if str, ok := order.(string); ok { orders = append(orders, scope.quoteIfPossible(str)) - } else if expr, ok := order.(*expr); ok { + } else if expr, ok := order.(*SqlExpr); ok { exp := expr.expr for _, arg := range expr.args { exp = strings.Replace(exp, "?", scope.AddToVars(arg), 1) @@ -912,7 +912,7 @@ func (scope *Scope) updatedAttrsWithValues(value interface{}) (results map[strin for key, value := range convertInterfaceToMap(value, true, scope.db) { if field, ok := scope.FieldByName(key); ok && scope.changeableField(field) { - if _, ok := value.(*expr); ok { + if _, ok := value.(*SqlExpr); ok { hasUpdate = true results[field.DBName] = value } else { diff --git a/search.go b/search.go index 901385956..7c4cc184a 100644 --- a/search.go +++ b/search.go @@ -98,7 +98,7 @@ func (s *search) Group(query string) *search { } func (s *search) Having(query interface{}, values ...interface{}) *search { - if val, ok := query.(*expr); ok { + if val, ok := query.(*SqlExpr); ok { s.havingConditions = append(s.havingConditions, map[string]interface{}{"query": val.expr, "args": val.args}) } else { s.havingConditions = append(s.havingConditions, map[string]interface{}{"query": query, "args": values}) diff --git a/utils.go b/utils.go index e58e57a56..d2ae9465d 100644 --- a/utils.go +++ b/utils.go @@ -58,15 +58,15 @@ func newSafeMap() *safeMap { } // SQL expression -type expr struct { +type SqlExpr struct { expr string args []interface{} } // Expr generate raw SQL expression, for example: // DB.Model(&product).Update("price", gorm.Expr("price * ? + ?", 2, 100)) -func Expr(expression string, args ...interface{}) *expr { - return &expr{expr: expression, args: args} +func Expr(expression string, args ...interface{}) *SqlExpr { + return &SqlExpr{expr: expression, args: args} } func indirect(reflectValue reflect.Value) reflect.Value {