GQL查询无法使用gcloud(google-cloud)和node.js

时间:2016-08-12 09:49:20

标签: node.js google-cloud-datastore gcloud-node

我正在尝试运行以下GQL查询:

function gqlExample(callback) {
  datastore.runQuery({
    gqlQuery: {
      queryString: 'SELECT * FROM Person',
    }
  }).execute(function(err, result) {
    if (!err) {
      // Iterate over the results and return the entities.
      result = (result.batch.entityResults || []).map(
        function(entityResult) {
          return entityResult.entity;
        });
    }
    callback(err, result);
  });
}

我在下一页上找到了上面的例子: http://ec2-54-66-129-240.ap-southeast-2.compute.amazonaws.com/httrack/docs/cloud.google.com/datastore/docs/concepts/gql.html

它声明它是一个有效的node.js示例,但在运行查询时出现以下错误:

/Users/xxxx/relay-fullstack/server/data/campaign-datastore.js:245
  }).execute(function (err, result) {
     ^
TypeError: ds.runQuery(...).execute is not a function
    at Object.campaignSearchGql (campaign-datastore.js:265:6)
    at Test.<anonymous> (datastore-test.js:29:16)
    at Test.bound [as _cb] (/Users/xxxx/relay-fullstack/node_modules/tape/lib/test.js:63:32)
    at Test.run (/Users/xxxx/relay-fullstack/node_modules/tape/lib/test.js:82:10)
    at Test.bound [as run] (/Users/xxxx/relay-fullstack/node_modules/tape/lib/test.js:63:32)
    at Immediate.next [as _onImmediate] (/Users/xxxx/relay-fullstack/node_modules/tape/lib/results.js:70:15)
    at tryOnImmediate (timers.js:534:15)
    at processImmediate [as _immediateCallback] (timers.js:514:5)

我正在使用最新版本的google cloud for node:

"google-cloud": "^0.38.3",

有没有人使用gcloud和节点正确执行GQL查询?任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

这显然是数据存储区文档的缓存版本。那些Node.js片段正在使用名为googleapis的不同库:https://github.com/google/google-api-nodejs-client

另一个库gcloud-node目前不支持GQL。