Skip to content

Commit

Permalink
Rename expr type to make it public. (go-gorm#2604)
Browse files Browse the repository at this point in the history
  • Loading branch information
macklin-10x authored and jinzhu committed Oct 17, 2019
1 parent a8a530d commit 5b3e40a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
6 changes: 3 additions & 3 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5b3e40a

Please sign in to comment.