使用“like”运算符和OR子句

时间:2018-01-31 05:18:19

标签: eve

我一直在寻找解决问题的方法,但我找不到答案。 我在我的数据库中有这些数据

{
  "_items": [
    {
      "_id": "5a69bbbe085eb50006b7515b",
      "sku": "SAB-EM",
      "name": "Sabão em pó",
      "price": 12,
      "promotions": [],
      "_updated": "2018-01-25T11:13:02.000000Z",
      "_created": "2018-01-25T11:13:02.000000Z",
      "_etag": "49fda82778b967e008ba46f7600822e940abb92b",
      "_links": {
        "self": {
          "title": "Product",
          "href": "products/5a69bbbe085eb50006b7515b"
        }
      }
    },
    {
      "_id": "5a69bbc7085eb50006b7515c",
      "sku": "AMA",
      "name": "Amaciante",
      "price": 15,
      "promotions": [
        {
          "bundle_quantity": 10,
          "paid_quantity": 8,
          "_cls": "QuantityBundlePromotion"
        },
        {
          "bundle_quantity": 3,
          "paid_quantity": 2,
          "_cls": "QuantityBundlePromotion"
        }
      ],
      "_updated": "2018-01-25T11:13:11.000000Z",
      "_created": "2018-01-25T11:13:11.000000Z",
      "_etag": "2308eb7c8c597ee441229d593a545e7e61a30160",
      "_links": {
        "self": {
          "title": "Product",
          "href": "products/5a69bbc7085eb50006b7515c"
        }
      }
    },
    {
      "_id": "5a69bbca085eb50006b7515d",
      "sku": "DET",
      "name": "Detergente",
      "price": 2,
      "promotions": [
        {
          "minimum_quantity": 5,
          "discount_percentage": 0.15,
          "_cls": "DiscountForMinimumQuantityPromotion"
        }
      ],
      "_updated": "2018-01-25T11:13:14.000000Z",
      "_created": "2018-01-25T11:13:14.000000Z",
      "_etag": "73583c72a90bc8b89e30d9b7ab5b904cd78827a1",
      "_links": {
        "self": {
          "title": "Product",
          "href": "products/5a69bbca085eb50006b7515d"
        }
      }
    }
  ],
  "_links": {
    "parent": {
      "title": "home",
      "href": "/"
    },
    "self": {
      "title": "products",
      "href": "products?max_results=3"
    },
    "next": {
      "title": "next page",
      "href": "products?max_results=3&page=2"
    },
    "last": {
      "title": "last page",
      "href": "products?max_results=3&page=29"
    }
  },
  "_meta": {
    "page": 1,
    "max_results": 3,
    "total": 87
  }
}

当我使用http://0.0.0.0:3000/products进行搜索时,结果就是这样。 我的问题是,我需要使用类似运算符通过名称 sku 进行搜索。但我到处寻找并没有发现任何东西,我尝试过使用MongoDB格式,但它返回400.

当我运行http://0.0.0.0:3000/products?where=name=="SAB-EM" or sku=="SAB-EM"时,它会返回一些内容,但我仍然需要使用 like 运算符执行此操作,而不是文字。

PS:我无法访问python-eve配置。

韩国社交协会

2 个答案:

答案 0 :(得分:1)

您可能想要转义查询。尝试这样的事情:

http://localhost:5000/regions?where=name==SAB-EM%20or%20sku==es

答案 1 :(得分:0)

我知道这个问题很旧,但是: 如果您将python-eve与SQL(sqlalchemy)结合使用,则语句'or'和'and'与'like'为:

/resource?where={"or_": [
                             {"my_column1": "like(\"%value%\")"},
                             {"my_column2": "like(\"%value%\")"}
                        ]
                 }

要使用“ and”语句,只需将“ or_”替换为“ and _”