This is a patch for the beego version 1.7.1
The patch is used to add some filters for the json field of a postgresql, including:
- json_trav_gt
- json_trav_lt
- json_trav_gte
- json_trav_lte
- json_trav_eq
- json_trav_nq
After applying the patch, you can use the filter like this:
func JsonFilterTest() {
o := orm.NewOrm()
qs := o.QueryTable(new(Tag))
var tags []*Tag
qs = qs.Filter("data__json_trav_gt", "a", 1)
qs = qs.Filter("data__json_trav_lt", "a", 3)
qs = qs.Filter("data__json_trav_gte", "b", 2)
qs = qs.Filter("data__json_trav_lte", "b", 2)
qs = qs.Filter("data__json_trav_nq", "c", 2)
qs = qs.Filter("data__json_trav_eq", "c", 1)
qs.All(&tags)
fmt.Println(len(tags))
for _, v := range tags {
fmt.Println(v)
}
}
To apply the patch, clone the beego-1.7.1.patch to the $GOPATH/github.com/astaxie/orm/
, and just apply it:
$ git apply beego-1.7.1.patch
The gate of allowing only one argument is opened if the new filter starts with "json_", what we should do is to:
-
simply modifying the
operators
variable indb.go
(this can be treated as a flip, if a new filter is set totrue
in the map, then the new filter is acceptable) -
add a new filter map to the variable
postgresOperators
in filedb_postgres.go
(this provides the real meaning of the new filter if it is accepted already)