【问题标题】:Connect to Google Cloud Datastore from nodejs (seneca)从 nodejs (seneca) 连接到 Google Cloud Datastore
【发布时间】:2014-05-26 14:11:45
【问题描述】:

我正在尝试使用 node.js 和 Seneca 框架中的数据层功能连接到 Google Cloud Datastore。 Seneca 框架需要根据连接到数据库实例来创建到数据库的连接,传递如下信息:

name: '',
host: '',
port: ,
username: '',
password: ''

等等

有没有办法像典型的数据库实例一样连接到 Google 数据存储区,或者是通过 REST api 调用的唯一方法?

【问题讨论】:

    标签: node.js google-cloud-datastore


    【解决方案1】:

    目前对 Google Cloud Datastore 的身份验证支持仅限于 OAuth 2.0。见Getting started with Google Cloud Datastore and Node.js

    凭据在每个 HTTP 请求中传递。

    【讨论】:

      【解决方案2】:

      目前,使用 node.js 连接到 Google Cloud Datastore 的唯一方法是使用 REST API。

      使用google-api-nodejs-client,您可以访问数据存储对象:

      googleapis.discover('datastore', 'v1beta2')
          .withAuthClient(authCredentials)
          .execute(function(err, client) {
            if (err) {
              seneca.log.error(err);
            }
            datastore = client.datastore.withDefaultParams({
              datasetId: datasetid}).datasets;
          });
      

      此对象将类似于您的连接对象,您可以使用此对象将queries 设置为您的数据存储区。

      我写的seneca数据存储插件可以在here找到

      【讨论】:

        猜你喜欢
        • 2020-02-23
        • 2017-09-09
        • 2019-07-11
        • 1970-01-01
        • 1970-01-01
        • 2020-11-28
        • 2020-06-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多