Skip to content

Commit

Permalink
Refactor query_builder
Browse files Browse the repository at this point in the history
  • Loading branch information
minhduc140583 committed Jul 13, 2024
1 parent d616dd1 commit 1cf3cfa
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion query/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,14 @@ func Build(filter interface{}, resultModelType reflect.Type, arrFields []string,
} else if key == "like" {
query = append(query, bson.E{Key: bsonName, Value: primitive.Regex{Pattern: fmt.Sprintf("\\w*%v\\w*", psv)}})
} else {
query = append(query, bson.E{Key: bsonName, Value: primitive.Regex{Pattern: fmt.Sprintf("^%v", psv)}})
opr, ok2 := Operators[key]
if ok2 {
dQuery := bson.M{}
dQuery[opr] = psv
query = append(query, bson.E{Key: bsonName, Value: dQuery})
} else {
query = append(query, bson.E{Key: bsonName, Value: primitive.Regex{Pattern: fmt.Sprintf("^%v", psv)}})
}
}
} else if kind == reflect.Slice {
if field.Len() > 0 {
Expand Down

0 comments on commit 1cf3cfa

Please sign in to comment.