简体   繁体   English

从Node.js(Seneca)连接到Google Cloud Datastore

[英]Connect to Google Cloud Datastore from nodejs (seneca)

I am trying to connect to the Google Cloud Datastore using node.js and the data layer functionality present in the Seneca framework. 我正在尝试使用node.js和Seneca框架中提供的数据层功能连接到Google Cloud Datastore。 The Seneca framework needs to create a connection to a database as per connecting to a database instance, passing information like: Seneca框架需要根据与数据库实例的连接来创建与数据库的连接,并传递如下信息:

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

etc. 等等

Is there a way to connect to a Google Datastore like a typcal database instance or is the only way through REST api calls? 有没有办法像典型的数据库实例那样连接到Google数据存储,还是通过REST api调用的唯一方法?

Authentication support for Google Cloud Datastore is currently limited to OAuth 2.0. 目前,Google Cloud Datastore的身份验证支持仅限于OAuth 2.0。 See Getting started with Google Cloud Datastore and Node.js . 请参阅Google Cloud Datastore和Node.js入门

The credentials are passed along in each HTTP request. 凭据在每个HTTP请求中传递。

At the moment, the only way to connect to the Google Cloud Datastore, using node.js, is by using the REST API. 目前,使用node.js连接到Google Cloud Datastore的唯一方法是使用REST API。

Using the google-api-nodejs-client you can get access to a datastore object: 使用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;
    });

This object will be like your connection object and you can use this object to make queries to your datastore. 该对象将类似于您的连接对象,您可以使用该对象对数据存储区进行查询

The seneca datastore plugin I wrote can be found here 我写的seneca数据存储插件可以在这里找到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM