Rename expr type to make it public. ()

This commit is contained in:
macklin-10x 2019-10-17 08:44:34 -07:00 committed by Jinzhu
parent a8a530db5a
commit 5b3e40ac12
4 changed files with 10 additions and 10 deletions

View File

@ -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()

View File

@ -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 {

View File

@ -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})

View File

@ -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 {