【问题标题】:GQL query with Google Cloud Datasore使用 Google Cloud Datastore 进行 GQL 查询
【发布时间】:2017-01-16 04:36:42
【问题描述】:

Google Datastore Runquery提供http客户端执行GQL查询,如下:

POST https://datastore.googleapis.com/v1/projects/my-project-id:runQuery?key={YOUR_API_KEY}

{
 "gqlQuery": {
  "queryString": "SELECT * FROM User WHERE email = 'user@example.com'"
 }
}

但我收到如下错误响应:

{
  "error": {
    "code": 400,
    "message": "Disallowed literal: 'user@example.com'.",
    "status": "INVALID_ARGUMENT"
  }
}

但是,Google Cloud Datastore Http Client'Select * from User' 这样的简单查询完美配合。

那么,如何使用 Datastore Http 客户端执行此 GQL 查询?

【问题讨论】:

    标签: google-cloud-datastore gql


    【解决方案1】:

    您必须将 allowLiterals 参数设置为 true 或使用参数绑定(命名或位置)。

    请参阅以下文档:

    https://cloud.google.com/datastore/reference/rest/v1/projects/runQuery#GqlQuery

    所以如果你想在查询中允许字面量(常量值),你应该把请求改成

    {
     "gqlQuery": {
      "queryString": "SELECT * FROM User WHERE email = 'user@example.com'"
      "allowLiterals": true
     }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-26
      • 1970-01-01
      • 2014-03-02
      • 1970-01-01
      • 2020-01-27
      • 1970-01-01
      • 2019-03-22
      • 2019-06-25
      相关资源
      最近更新 更多